Creating an On/Off switch in Tableau

During the fourth day of dashboard week, I created a dashboard that showed what songs a person might like based on their preferences. The user had the ability to choose which preferences they wanted to include in the calculation for the song recommendations.

This required switches for parameters which would determine whether those parameters were used in the calculation or not. The calculation was to determine the difference between a metric value and what value the data actually had. There were several different metrics and I took the average difference of them to calculate a 'distance' between the preference they had and the song.

So how did I make sure Tableau knew when to include a preference or not?

It was by having a button link to a parameter which then linked to the calculation itself. The first step was to create the parameter itself. This was a simple string parameter with "On" or "Off" as possible values.

I needed a separate one for every metric that was in the calculation. Then, in the calculation I included a check to make sure that we were comparing the right metric and a check to see if the parameter was included or not. As a side note, the calculation is possible in this format because the metrics are pivoted to be in one field. It would be possible if they are in different fields too, but the calculation would look at little different.

Now if any of the parameters were set to "Off" the if statement would return a false so that piece of the calculation would never occur and that metric is essentially not included.

Next, we want a sheet for each of these parameters to be edited by through a dashboard action.

The two AGG(avg(1)) in the columns created a placeholder for both the On and Off button within the sheet. We add a field that just says 'On' in one of them along with a field that says 'Off' in the other one. This lets us have a value to fill into the parameter in a dashboard action. We also need to add a calculation to change the colors so the user knows when either 'On' or 'Off' is selected based on the color of the button.

We add that calculation to color and now the color of the buttons will change based on the selection of the parameter. We also need to manually change the colors in each setting by choosing what colors we want when the switch is on and what colors we want when the switch is off.

Lastly, we want to add two dashboard actions for each of these buttons. One that will fill the parameter with "On" and another that will fill it with "Off"

You can see these buttons in action here.

Author:
Sakif Chowdhury
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
© 2025 The Information Lab