In the world of Tableau, the power of Parameters is well known. Parameters can be used for a plethora of ways to enhance interactivity and user experience, but sometimes you run in to situations where the feature set surrounding Parameters doesn’t quite meet your needs. However, with recent(ish) additions of Parameter Actions, there are many more creative ways you can get around these. This article explores one of them.
We’re going to talk about how you can set the value of a parameter (or parameters) based on the value of another parameter, using a custom button and parameter actions.
For example, let’s say you’re creating a Monthly Project Report, where your users only look at a single project at once (but wish to change between them), and only care about a single month at once (but wish to switch as well). The latest month is the most important one to look at, and so should be the default.
You may want to add a ‘Reset’ button to the Month selection, which will default it back to the latest date available for the selected project. This would be easy if it were always just today’s date. But what if the default month is different for each project? In this case, you will need to determine the ‘default’ month for each project, and set it on-click of the reset button.
Creating the Button
The dank, dark, and dirty secret of this trick is using a sheet (set to a Shape) that mimicks a button, creating a calculation that determines the latest month (using LOD for the project), and setting a parameter action to be driven on click.
Here’s some basic dummy data we can use as an example:
As you can see, Docklands Park goes up to August 2020, whereas Ferryville Trifecta only goes to May 2020.
I have done a few things to set up for this. I have created:
- Two parameters, one for Project and one for Month/Year.
- A calculated field that creates a date from the month and year
- DATE(STR([Year])+’-‘+STR([Month]) + ‘-01’)
- A calculated field for the Project parameter (if Project = Project Parameter)
- A sheet that contains the MAX Month Date for the selected project (using the above parameter calculated field on the filter)
This enables the following:
With this sheet, we will turn this in to a button. I’ll change it to a shape, and add an ASCII character of an arrow that resembles a reset button e.g. ↺.
Quick tip: You can find ASCII characters for all sorts of things at http://www.amp-what.com/ - this is the best resource for ASCII characters I have found so far.
The resulting button looks something like this:
Of course, you can make it look however you like within the constraints of Tableau. For example, it could be a labelled buton like this:
Further to this, we can also make the button only show up when it is appropriate. To do this, we make a calculated field that checks if the currently selected Month parameter is equal to the max month for the Project. Then, we exclude that value, so that the sheet is blank when it is already selected (and shows up when we have selected a month other than the latest).
The last step is to create the Parameter Action that sets the month back to default.
This gives us our reset button:
Other Thoughts and Improvements
This would ideally be added to a Show/Hide container section for the user to change their parameter selections and then ‘apply’ them. The reason being is that once they change project, the month doesn’t automatically change. And, as you can see, you can select months that are not available for that project. It would be better to have them select their project and month at once, and then have warnings if the month isn’t available, and perhaps set the parameter to the latest date even if the wrong one is set.
That is, in order to change the project, you will also need to click a button, which can be used to reset the date.
This can be used for various other use cases, so I am keen to hear and see how you have managed to apply this principle.