Ever wanted to change a parameter with a click of a button in Tableau? While there’s no built in parameter button option in Tableau (sadly), with an extra sheet and a few parameter actions you can build something that does the job. In this post, I’ll take you through a method for building a parameter-changing button that creates a smooth and intuitive experience for your users.
Why might you want to change parameters on a button-click? Parameter changes allow lots of different functions in Tableau to work, but my biggest use case (by a mile!) is to control dynamic zone visibility. I use this in almost all of my dashboards to allow more user interaction. For an example of lots of parameter buttons in action, check out this recent viz, “Hey, It’s That Guy”, which uses parameter buttons to open and close new views, conduct a survey, and submit responses.
Now that you’ve seen parameter buttons in action, let’s learn how to build them!
(Tip: This post will focus on making a single button, with no need to change your data source. If you want to create a row of icons or buttons all on the same sheet, and are willing to do a little data modelling, check out this post instead.)
My Setup
Before I dive into this method for creating a parameter change button, let’s take a quick look at the setup I’ll be working with in this example. (In your own use cases, you’ll have your own parameters that you want to change – I just want to give you context about the example that I’m using to make it easier to follow along.)
I’ve created a simple parameter called “Color” with two values, “Red” and “Blue”. I’ve also created a sheet with a shape, where the color is set by the parameter (using an extra calculated field). I’ve added the sheet to a dashboard.
If I change the parameter, the shape changes color – now I want to create a button to do that change.
Let’s build!
Step 1: Create a new sheet
Start by creating a new sheet, and giving it a descriptive title.
Step 2: Set Up the Parameter Target Field
Next, we need to set up a field that will tell the parameter what to change to when we click the button. You have a couple of options here. If you want your button to always do the same thing (for example, always change “Color” to “Red”), you can set it up like this:
It’s important that your calculated field exactly matches the value in your parameter – if your parameter is a string, it should be a string, if it’s a number, it should be a number, etc.
Or maybe you want your button to toggle between two options. (Ex: If the circle is red, change it to blue. If the circle is blue, change it to red). In that case, we’ll set this up a little differently. Our calculated field will now use the current state of the parameter to decide what value to change the parameter to:
If you had a parameter with more than two options, you could even go crazy and add a whole bunch of conditionals to this calculated field – I usually see this used for a “scroll arrow” type of setup – but this isn’t common. Typically, you’ll either use a single value or a toggle.
I want my parameter to toggle between red and blue when I click the button, so I’ll use the “Toggle Color” field instead of “Change Color to Red” in the rest of this example.
step 3: Additional Calculated fields
First, we’ll need to set up a couple of extra calculated fields. First, create a calculated field called “True”, and enter the boolean value TRUE.
Then create a calculated field called “False” and enter the boolean value FALSE.
Step 4: Set Up Sheet
Now that our calculated fields are ready to go, we can add them to our sheet. Add the “True” and “False” fields and the parameter target field you created to the “Details” shelf of the sheet.
Step 5: Format Sheet into button
Now it’s time to format your sheet. You have lots of options here – your button could be text-only, use an icon or shape, use text and a background, or even just be transparent so that you can overlay it on an image on your dashboard.
If you want to add text to your button, you’ll need to drag the parameter target field you created onto the “Text” shelf and change the mark type to “Text”. Then you can edit the text to say whatever you want:
Right click on the sheet and use the “format” option to set additional formatting, like background color and border.
(Hint: If you want a transparent button to float over other dashboard components, delete all the text in the text edit pane and change the background to “None”. Alternatively, import a transparent shape as a custom shape and use that in the shape pane).
For my button, I’ve made the background grey and given it a border. Don’t worry about the sizing – we’ll fix that on the dashboard.
If you want your button to be a shape instead of text, no problem – just change the mark type to “shape” and select the icon you want. (You can even bring in a custom shape here if desired).
This is a good time to edit your tooltip as well – make it something that describes what the button does.
step 6: Add To dashboard
At this stage, we can go ahead and add the sheet to the dashboard. Hide the title, and set sizing and padding as appropriate. You’ll probably want to set your view mode to “Entire View” as well for more control over the sizing.
(I also went back and changed my text to be bold and centered during this step, because I forgot it earlier!)
Your button can be floating or tiled, whatever works best for your use case. You may need to add blank objects to its container or fix the height to get it displayed how you want.
Step 7: Parameter Change Action
We’ve made it to the exciting step! Let’s add the parameter action that will make our button actually work. From the “Dashboard” menu, select “Actions”.
Click “Add Action”, and choose “Change Parameter”.
Give the action a descriptive name. From the “Source Sheets” menu, select only your button sheet. Set ‘Run action on” to “Select”.
Set the “Target Parameter” to be the parameter you want to change – in my case, it’s “Color”. Then set “Source Field” to be the parameter target field that you created and added to the sheet. For our example, that’s “Toggle color”.
Set “Clearing the selection will” to “Keep current value”. Then select “OK”.
Step 8: Add De-Highlighting action
Our button should now be working! When you click on it, the parameter will change. However, you’ll notice that the first time you click on the button it highlights, and you have to click it twice more to get it to toggle again. No good!
Our last step is to add another action (a filter action this time) that will get rid of the highlighting. Luckily, we added “True” and “False” fields to the sheet earlier, so we’re ready to go!
Open the “Actions” dialog again, but this time select “Filter”.
For the “Source Sheets” section, select dashboard in the dropdown. Select only the checkbox next to your button sheet. Set “Run action on” to “Select”.
For the “Target Sheets” section, select the button sheet from the dropdown. Important: Don’t select the dashboard and then the sheet – select the sheet directly.
Set “Clearing the selection will” to “Show all values”.
For the “Filter” section, choose “Selected fields”. Set the “Source Field” to “True” and the “Target Field” to “False”.
Click OK, and you’re done! Your button should now change the parameter on-click, and will automatically get rid of its own highlighting.
(Note: If you’re dealing with a very large dashboard with more of a performance load, you may see the blue highlight appear for a second or two before it clears. To avoid this, you can create the button as a transparent shape and float it over another dashboard element – the Flerlage Twins have a great blog post about transparent shapes here. If you’re using your button as a toggle, you’ll still want to go through the highlight-clearing steps above to avoid needing to click the button twice to activate it; however, the highlight won’t be visible even for a second).
Advanced Tip: If you have a toggling button, you might want it to look different depending on which state it’s in. (For example, an “on/off” button). If you’re formatting the button all on one sheet, like we did above, you can use your parameter target field to format color and shape; or, if you’re using the button as a transparent object that floats above other dashboard objects, you could use dynamic zone visibility to switch between two objects displayed below the button.)
I hope you enjoyed this post, and learned a cool method for creating parameter-changing buttons!
Leave a Reply