Parameters were one of the things I could not get my head around before I started Data School. I just couldn't understand why and where would you use them? But, after hours spent learning parameters and using them on my dashboards, now I can see that parameters are a powerful tool that allows you to make dashboards much more interactive.
One of my favourite use cases of parameters is using them to switch between different charts within your view. This helps you save space on your dashboard, makes it more interactive and gives the user sense of control over what is happening on the dashboard. And today, I will show you how to do that!
For this example, I used the Sample Superstore dataset, which comes together with Tableau. Here is a short walk-through on how you can connect to one, in case you want to follow along. Alternatively, you can just download my workbook from Tableau Public.
First, I created three different charts all displaying sales by state, which you can see below:
Then, I created the parameter we will use for this example. To do so, click the bottom-pointing arrow next to your search bar within the data pane and select Create Parameter.
On the window that opens, give your parameter a name (I named it "Select the chart type"), change the data type to a String, change allowable values to a List and type in the options you wish to display on a parameter. I wrote Bar, Map and Table:
Click OK. Your parameter should be displayed at the bottom of the data pane under the Parameters shelf.
After this, it is time to create three calculated fields that we will use to swap between the charts. Let's go back to the data pane, click the downward-pointing arrow again and choose Create Calculated Field. Within the calculation window, type the conditional statement, as per below:
This will check whether the option "Bar" is selected on your parameter, if yes, it will return True, if not it will return False.
Repeat the same for the other two chart types:
After this, navigate to the sheet with the bar chart. Find your parameter in the data pane, right-click it and choose Show Parameter. It will appear on the top right corner of your worksheet canvas. Make sure that the option selected on your parameter matches the chart on the display. In this case, it should be "Bar". Then drag the "Is it a Bar?" calculated field onto the filters and tick True. After you finished, click OK.
Go to your other two sheets and repeat the process. Again, make sure that the parameter option selected matches the chart on the display, "Map" for sheet 2 and "Table" for sheet 3.
After this, it is time for the final step, bringing the sheets onto your dashboard. To do that create a new dashboard and bring in a horizontal container (for the switch to work, all of the sheets must be in the same container). After that drag the sheets into that container side by side. You should be able to see a view similar to the one below:
Only one chart should be displayed based on the parameter selected. If you switch between the parameter options, you should be able to see how the displayed chart changes from a bar to a map to a table. However, we don't want that blank space the chart leaves after it gets deselected. For that, we need to hide the titles of all of the charts. However, before we do that it is useful to check whether any of our charts are fixed in width. You can check this by left-clicking on the chart and selecting the drop-down menu on the right of the chart. If Fixed Width is selected, deselect it.
After you made sure that none of the charts is fixed in width, you can hide the titles, by deselecting the Title option on the same drop-down menu.
And that is it, you have an interactive dashboard that allows swapping between different chart types. Go and try it out!