KNOWLEDGE BASE

Returning Profit for Current and Previous Year Using a Parameter


Published: 27 Feb 2014
Last Modified Date: 29 Nov 2019

Question

How to return the profit for current and previous year using a parameter to choose current year.

Environment

Tableau Desktop

Answer

Step 1 - Create the parameter:

  1. Right-click the Parameters pane and select Create Parameter....
  2. Name the parameter This Year.
  3. Under Data Type select Integer.
  4. Under Allowable Values select List.
  5. Enter 2010, 2011, 2012, and 2013 in the list of date values.
  6. In the Display Format drop-down menu, select Number(Custom).
  7. Enter 0 for the number of decimal places.
  8. Clear the selection for Display thousands separator.
  9. Click OK.
  10. Right-click This Year and select Show Parameter Control.

Step 2 - Create the calculated fields:

  1. Go to Analysis > Create Calculated Field....
  2. Name the calculated field This Year Profit.
  3. In Formula enter IF YEAR([Order Date]) = [This Year] THEN [Profit] END.
  4. Repeat steps 1-3 with name Last Year Profit and formula IF YEAR([Order Date]) = [This Year] - 1 THEN [Profit] END.

Step 3 - Build the view:

  1. Drag Customer Segment to the Rows shelf.
  2. Drag This Year Profit to the Column Shelf.
  3. Drag Last Year Profit to the Column Shelf.

Additional Information

To view the above steps in action, see the video below. 
Note: the video is silent. 


Discuss this article... Feedback Forum
Did this article resolve the issue?