Parameters can be incredibly useful when creating dashboards, especially when we want our users to interact with the dashboard to investigate a dataset.
I first came across parameters when making my Data School application viz; with some trial and error, I made a simple ‘Top N’ parameter, allowing the user to change the value of N to see as many or few top records as they liked.
However, it was only after attempting a Workout Wednesday challenge in week 2 of DS30 that I realized I had misunderstood how exactly parameters work…
What are parameters?
Parameters are user-controlled variables: a user can select an option from a toggle or drop-down list, or type in a specific value, and the dashboard will change to reflect this input.
Parameters tend to be single-select. They are different to Filters in Tableau: while Filters will usually narrow down what the user can see on the dashboard, Parameters are simply changing what the user can see – the amount of datapoints being represented might go up, go down, or stay the same.
Think of it this way: a Parameter on its own is like a light switch. It can be operated by a user to change from ‘on’ to ‘off’, but it needs to be connected to something else – i.e. a lightbulb – in order to have an effect.
We might use our Parameter in a Calculated Field, with a Filter, to create a Reference Line or Band, or to show and hide charts in our dashboard.
Easy mode: viewing Top N results
Using a dataset like Superstore, we might want to figure out which of our products are currently generating the biggest sales figures. I’ve made a simple bar chart below looking at ‘Product Name’ and ‘Sales’, and sorted to see the top values; however, there are almost 2,000 different products in this dataset, and the user might not be interested in scrolling through them all.
In the Data Pane, click the drop-down arrow and select ‘Create Parameter’; in this example, we might want the user to be able to choose from a set range of values that are whole numbers (Float).
We can choose a default value for our Parameter using the ‘Current value’ box.
Once we have set up our Parameter as planned, it will appear at the very bottom of the Data Pane: right click it and select ‘Show Parameter’ to make it appear in the view.
We can now use this Parameter with a Filter, to let the user choose how much we narrow down what our dashboard will show. Ctrl + click the ‘Product Name’ pill in our Rows shelf, and drag onto the Filter card. This is a ‘Top’ Filter that is looking at a particular field (‘Product Name’), so we go to the ‘Top’ pane in the Filter menu and select ‘By field’, then choose our new Parameter in the appropriate drop down menu.
It should now be possible to change the number of top product names we see in the bar chart, simply by dragging the slider left and right.
Hard mode: changing our query pipeline
What happens if we add another Filter?
For example, say our users are specifically interested in the Technology products, and which are generating the biggest sales figures. Dragging ‘Category’ onto the Filters card, select ‘Technology’.
The Parameter is still set to show the top 5 product names, but suddenly there are only two bars in our chart…
This is due to an Order of Operations issue. Tableau is applying our Top N Parameter Filter to the data to output a top 5 values, and is then applying our ‘Category’ Filter on those top 5, narrowing it down to show only the 2 products in the ‘Technology’ category.
You can investigate the Order of Operations in more depth here.
In this example, we can choose to move the ‘Category’ Filter to an earlier point in our Order of Operations – for instance, by making this a Context Filter.
Right click on the ‘Category’ Filter, and select ‘Add to Context’.
We should now be able to view the top N ‘Technology’ products, using our Parameter slider to set the N value.