Switching your Dimensions and Measures using Parameters in Tableau

In the DS27 cohort, we are on our second week using Tableau, and earlier this week we had an afternoon crash course on using parameters effectively by Lorna. In this post, I will cover one of the simple yet effective ways you can use parameters to give your end user a greater degree of control in your viz, allowing them to choose what dimension and measures they can use to break up their data.

First things first, lets start with a simple bar chart using the Sample Superstore data that comes with all versions of Tableau Desktop and Public.

A simple bar chart with SUM(Sales) on the columns, and Sub-Category on the rows, but how do we give the end user more control?

Let's say we now want to see our sales broken down by different dimensions such as the manufacturer, or even product name; but we don't want to create a second chart. For that, we need to create a parameter. Below your data sources, you will find a carrot, click on that and now select 'Create Parameter...'.

Upon clicking the option, we will be greeted with the 'Create Parameter' screen. Here we have a lot of options on how to build our Parameter. Our first is data type. Here we have a lot of options, but for our purpose we want to choose the String option.

We then want to choose the List option from 'Allowable values', and re-name the parameter to something you'll remember. For this demonstration I chose 'Dimension Switcher'. This will then bring up a window at the bottom where you can assign your values. You will want to name your values the same name as your dimensions your user may want to view. You can do this in any order, but pay attention to your spelling, as that will become important later.

When you're finished, your Parameter options should look something like this.

Great, you're now over halfway through! Tableau now has a list of dimensions that your user can select, but doesn't know what to do with them. So, let's tell it how to use this parameter by creating a calculated field. You can do this under the same menu where you first selected 'Create Parameter...', or you can right-click on your newly created Parameter and select 'Create' -> 'Calculated Field...'.

Within this calculated field you now want to tell tableau what value in the Parameter relates to which dimension. You can do this by using the CASE function. CASE [Parameter Name] WHEN 'Dimension Value' THEN [Dimension Name]. Note that the dimension value needs to be spelt exactly the same as in the parameter (including capital letters) otherwise it will not work.

Here's what our calculated field should look like.

After you've completed this step, we can now add our Parameter to the dashboard. Do this by right clicking on the Parameter and click, 'Show Parameter'. You can then copy the steps above for your measures. Also, make sure you put in your new calculated fields in place of your original dimension and measure, and now your viz is now multiple charts in one.

You're all done! This is just one way you can use parameters creatively in Tableau, and one that I will definitely be using more in the future.

Author:
Carlo Sanzeri
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2024 The Information Lab