Tableau’s Custom Table Calculation


Let’s use the Superstore dataset from Tableau to create an example of a custom table calculation. We’ll look at Sales for each Region and each sub-category. We’ll start with a table.

Tableau's Custom Table Calculation

Let’s create a custom table calculation that gets the change (difference) in the Region’s sales for each of the sub-categories. The calculation will be called Sales Difference. Below is the screenshot of the calculation’s formula.

Custom Table Calculation - Sales Difference

ZN(Sum([Sales])) - LOOKUP(ZN(SUM([Sales])),-1)

The ZN or zero number function returns a value of zero if the number is null or empty. If the number is not null, then Tableau returns the same number. The LOOKUP function will find your specified value, and the minus one tells Tableau to look one partition back.

If we go back to the original table at the top of this post, we can see that the sales for bookcases for the Central region is 24,157 and the sales for the East region is 43,964. That’s a difference of 19,807. Our custom table calculation will be able to show these differences in the table. We’ve already created it so all we need to do is drag it over to the table and Tableau takes care of the rest.

The delta (triangle) icon in the pill of our newly-created custom table calculation means that it is a table calculation. The upper-case delta (Δ) often signifies “change” in the field of mathematics and is the fourth letter of the Greek alphabet.

Change the Order of the Regions

Currently, the Regions are: Central, East, South and West. Suppose you want the following order: East, West, Central and South. Click on the Region pill in the Columns and choose Sort… from the drop-down menu. We can sort manually.

Sort Regions

After you click Sort in the menu, the dialog box shown below appears. Choose Manual from the drop-down and click on the region names and the arrows to move the names up and down as you wish, then close the dialog box.

You can choose to sort manually by clicking Manual in the drop-down. The other options are Data Sort Order, Alphabetic, Field, and Nested. Your table will now resemble the following screenshot.

Custom Table Calculation Sorted

Leave a comment

Your email address will not be published. Required fields are marked *