How to Compute Year over Year Comparison with a Parameter to Change the Year

Published: 04 Dec 2023
Last Modified Date: 05 Dec 2023


How to compute a YoY comparison with a parameter to switch the year.


  • Tableau Desktop


To review the steps listed below see the sample packaged workbook in the Attachments section of this article.

1. Create a parameter to change the year:

Name: Switch Year (Current Year)
Data type: Integer
Allowable values: List
User-added image

2. Create a calculation called Sales - Current Year to get the sales of current year using the following example:

IF YEAR([Order Date])=[Swith Year (Current Year)] THEN [Sales] END

3. Create a calculation called Sales - Previous Year to get the sales of previous year:

IF YEAR([Order Date])=[Swith Year (Current Year)]-1 THEN [Sales] END

4. Add Sales - Current Year and Sales - Previous Year to Rows, then right-click on the second measure and select the Dual Axis option:

User-added image

5. Change the Marks type to line or area chart on the Marks card to improve the visualization.

User-added image
User-added image
Did this article resolve the issue?