fbpx
Ynteractive logo

Tableau: How to Filter Dates While Calculating % Difference

Filters can cause problems when using table calculations in Tableau. Here’s a trick to use a filter while also using table calculations. We’ll use the lookup function to force the filter to be applied after all other calculations.

Tableau: How to Filter Dates While Calculating % Difference - step 1 screenshot

Step 1:

Build a line chart using Month([Date]) and sum([Sales])

Tableau: How to Filter Dates While Calculating % Difference - step 2 screenshot

Step 2:

Copy the sales pill, and add a quick table calculation; Percent Difference

Tableau: How to Filter Dates While Calculating % Difference - step 3 screenshot

Step 3:

Add a filter for the year 2020 only. The data is now filtered to 2020, but January is missing a percent difference value. The table calculation will not work when data is filtered out.

Tableau: How to Filter Dates While Calculating % Difference - step 4 screenshot

Step 4:

In order to avoid the filter, use the lookup function to create a filter as a table calculation instead. Now, the filter will be applied after the percent difference is calculated.

lookup(max(DATEPART(‘year’, [Order Date])),0)

Tableau: How to Filter Dates While Calculating % Difference - step 5 screenshot

Step 6:

Convert the new filter to discrete and drag it to the filter shelf. Now, January is displaying a value.

Tableau: How to Filter Dates While Calculating % Difference - step 6 screenshot