Parameters are values generated by the user of the worksheet or dashboard. Parameters are not part of the dataset.
In Tableau, parameters are dynamic values used to replace the following:
- constant values
- filters
- reference lines
In computer programming, a parameter is a variable in a function definition. It is a placeholder and hence does not have a concrete value. An argument is a value passed during function invocation. When you first define and write your function, you give it parameters, often within a set of parentheses separated by commas, however, parameters are optional.
Suppose you want the user of the chart to be able to select a threshold. All values above the threshold are “High” and those equal to and below are “Low”. This is one use case of the parameter. To expand on this use case, imagine a map of the United States where we are showing profit made in each state. We want low profits to be grey and high profits to be green. The user can enter the threshold value and the map’s state color will change dynamically.
Another use case would be showing the top 10 products by profit. The use could change the 10 to a number of their choice.
Superstore Profit Map with Parameter
We want to show a map of the sates that are color-coded by a threshold that the user can set. When profit is above the threshold, it will be one color, and below another color.
We can create a profit parameter and call it Profit Parameter. How? Right click the Profit pill in the Data pane under Measures and select Create > Parameter… You will the the dialog box (or something similar depending on your Tableau version) below. Give it a name. I chose Float as the data type and 1000 for a starting value. Later, on the graph, we will show the parameter so the user may change it.
The parameter we created is listed in the Parameters section of the Data pane. Parameters are global across a workbook and can be used in any worksheet.
To actually use the parameter we will create a calculated field that returns “High” if our profit is above or equal to the parameter (of 1000 initially and whatever the user chooses after that) or otherwise “Low”.
Calculated Field
Let’s create a new “column” of data by creating a new calculated field. This field will be categorical (not quantitative). This is the cool part because we can use IF statements and reference the current value of our parameter. Lets right-click on our data pane and select “Create calculated field”. Let’s call this new field Profit Category, and create our calculation.
IF (SUM([Profit])) >= [Parameters].[Profit Parameter] THEN "High" ELSE "Low" END
We now have a new blue pill with an icon of =Abc.
Build the Map
Let’s drag our State/Province category onto our worksheet, and Profit onto our label. Now, we see the total profit for each state.
Drag our Profit Category pill to the Color card we see that Tableau categories each state into one of two colors. The color choices of blue and orange can be changed by clicking the Color mark and choosing the category and color. If we right-click on our parameter and choose Show Parameter then the user will be able to change the value.
If the user changes the profit parameter to 5,000 (from 1,000), the map will dynamically change the colors, as you can see. We’ve redefined what “Low” means. Now, any profit below 5,000 is considered to be low and will be coloured orange.