KNOWLEDGE BASE

Show Previous Year Sales When Filtering Down To A Single Year


Published: 21 Nov 2017
Last Modified Date: 21 Nov 2017

Question

How to calculate and show previous year sales when filtering down to a single year.

Environment

  • Tableau Desktop

Answer

DCreate two calculations:
 
Previous Year Sales 
LOOKUP(SUM([Sales]),-1 ) 

   and

!DateFilter 
str(LOOKUP(max(DATEPART('year', [Order Date])),0)) 

Note: It is not necessary to wrap the !DateFilter calculation in a string, but it removes the commas and makes it look more like a date. 

By Using the !DateFilter on the filters shelf (make sure to change to Discrete), you can filter the view down to just a single year, and have our Previous Year Sales as a measure value underneath our regular Sales. 

See the example workbook for how to use these calculations .
Did this article resolve the issue?