You may want to create a view that shows how the values of two measures compare against each other. But what if you also wanted to be able to choose which measures were being compared—or better yet, add a control to the view that would let any user select the measures to be compared. You can create such a view using parameters and calculated fields. The calculated fields replace the measures in the view and can be set interactively by the user with parameter controls or parameter actions.

There are 3 main steps to do this: Create a parameter, create a calculated field to measures in the view, and set-up the view. This example will use the same data from the Star Wars API from my Dashboard Week: Day 2 blog.

Step 1 – Create a parameter:

  1. In the Data pane, click the drop-down arrow in the upper right corner and select Create Parameter.
  2. In the Create Parameter dialog box, do the following:
    • Name the parameter (eg. “Select Measure”:)
    • Set the data type to string. (You can also select integer which can make it quicker to write the formula in the calculated field but this can be confusing for beginners)
    • Skip down to the allowable values field, and choose list.
    • Type individual measure names in the List of values area: eg ( “cost”, “speed”, “length”)
    • Click OK to close the Edit Parameter dialog box

***Pro Tip: If you want to create a second parameter simply right click the first and select duplicate.

Step 2 – Create a calculated field to change the measure in the view

  1. Choose Analysis > Create Calculated Field to open the calculation editor. Name the calculation and type or write the pictured formula
  2. Click OK to exit the calculation editor.

Step 3 – Set up the view:

  1. Drag one of the calculated fields to Rows and one to Columns
  2. Drag the dimension you want to Detail.
  3. In the Parameters area of the Data pane, right click the parameters you created and choose Show Parameter Control.
  4. Tableau displays the parameter controls beyond the right side of the view by default. Drag them over to the left side to make them easier for your users to see.

You can also use a similar method to this to change measure aggregations. Tune into the blogs to find out how to do this another time!

The Data School
Author: The Data School