Learn what the Data School Learns: An Introduction to Parameters

by Hannah Murphy

This week DS24 took part in 'Learn what the Data School Learns', running an online session on either Tableau or Alteryx for the public. Although this was not my first experience teaching it was still a daunting prospect, especially as I had never run a session online.

My topic was Parameters and although I have been using them since my initial application, it's one thing to understand a technique well enough to implement it myself but completely different when it comes to teaching. Thankfully we had a Parameter session in our Tableau training a couple of weeks ago which was fantastic in giving me some inspiration when planning my own session.

The purpose of this blog is to go over the very basics of what I covered in my session, looking at setting up basic parameters and using calculations to dynamically update your visualisations.

What are Parameters?

Tableau defines a parameter as a workbook variable such as a number, date or string that can replace a constant value in a calculation, filter or reference line. This is a user-generated value that works independent of the data source. By this we mean that the user can select the parameter values without having to use a field name from the original data, they can be used to increase interactivity and understanding in a viz.

Using a Parameter to filter the view by a dimension

Parameters can be used to replace a basic filter in sheet or dashboard and are relatively simple to set up. To do this we right click on the dimension we want to filter by, select 'create' and then 'Parameter'. This will open the parameter set-up window:

As we went via the dimension to create this, very little needs to be done here. Make sure the parameter is named something sensible and click OK. Right click on your new parameter pill on the left-hand side and click 'show parameter'.

However, you will notice that changing the value of your parameter doesn't effect your view. This is because you haven't set up your view. To do this we need to create a simple Boolean calculation:

By doing this we are telling Tableau that when the value selected on our parameter matches the value in the Region field of the data then return the calculation as 'True'. By dragging this calculation onto our filter pane and selecting 'True', we are now filtering our sheet by the parameter value. In this sense we haven't achieved much more than a standard filter. However, if we didn't want to include all the values under our dimension - for example if we only wanted the user to be able to display data from 'East' and 'West', we would need a parameter as this cannot be achieved with a basic filter.

Using a Parameter in highlight calculations

The same calculation can also be used in a slightly different context. For example, if we had a line chart with multiple lines, it is sometimes hard to differentiate between the different lines. By dragging out 'Region Parameter Calc' onto colour instead of the filter pane, Tableau will return a different colour for when the calculation returns as 'True'. For this to work the original dimension also needs to be on detail.

This is also a great opportunity to include a dynamic title. To do this, simply open the title editor and insert your parameter from the 'insert' tab.

This will now update the text highlighted in grey to show the value selected in your parameter.

Using a Parameter to change the measure

Parameters can also be used to switch between multiple measures of different aggregations. To do this we need to create a custom parameter:

Create a new parameter and name it something sensible. As we are entering a list of text values our data type needs to be 'string'

Once we have created our parameter, we need to tell Tableau what to do with it, for this we need to set up one of two calculations:

This is a matter of personal preference. I prefer to use a CASE statement but the same can be achieved with the below IF statement:

In both of these calculations, the grey text in quotations needs to be identical to the string value entered when setting up the parameter. Remember Tableau is case sensitive.

We can now use this calculation to replace our measure when building our chart:

As a general rules we want our chart to be sorted in descending order based on the value. As it is currently set up, the sort order will not be updated with the parameter. However, by right clicking on the blue dimension pill and clicking on sort we can change this:

By setting up your sort as above, you have told Tableau to adjust the sort based on the measure selected in your parameter.

And there we have it, the very basics of parameters. Naturally, this has only just scratched the surface of what parameters are capable of. To look at parameters in more detail and to learn a few more advanced use cases then I  would recommend looking at the resources listed below.

Useful resources:

The Data School blogs:


https://www.youtube.com/channel/UC5KQSLxuu1MkXjlwcucAWsg https://www.youtube.com/channel/UCTlX7UpqASrldmx5_CpG3CA

Tableau community: