I previously wrote a blog post showing how you can create a selection panel using Set Actions. After some recent experiments with using a parameter as a data source (more on that here), and with some inspiration from Lindsey Poulter (see below), I decided to recreate a similar selection panel using parameter actions for this week’s #MakeoverMonday challenge.
Why Use a Parameter Action?
The set action approach is very effective and has the advantage of easily being able to select multiple adjoining values, however, it has the disadvantage that if you want to select multiple values sequentially, you have to remember to hold down the CTRL key otherwise you will lose all previously selected items. For example, here I don’t hold CTRL when selecting Connecticut so I lose my prior three selected states:
When using a parameter as a data source you have more control over the behaviour of each parameter action and how the value stored in the parameter updates as a result.
Selection Panel Requirements
For this #MakeoverMonday dashboard, I want to show a list of NBA teams and be able to select up to nine teams with the following requirements:
- If the team being clicked on is already selected, then deselect it (remove it from the parameter)
- If the team is not already selected and there are fewer than 9 teams already selected, then make the team selected (append the team to the parameter)
- If there are already 9 teams selected then don’t add the team to the parameter and display a warning/instruction in the tooltip that the maximum number of teams has been selected
Value to pass to the parameter
The above requirements (except for the tooltip) are achieved with the below calculation, the result of which I pass back to my p.Selected Teams parameter when a team is selected in the view:
Below is the setup for the parameter action:
Dynamic Tooltip Instructions
The final requirement is to show a message in the tooltip if there are already nine teams selected (as I’ve designed the small multiple for my dashboard as a 3×3 grid). This is achieved by adding the following calculation to the tooltip shelf:
The Teams Selected calculation is below. This counts the number of team names currently in the parameter by replacing all characters except the tilde (~) delimiter with an empty string, which results in a string of tildes – one for each team name. The length of this string is then calculated:
Building the View
There are different ways you could construct this view. In this case, I used a series of bar charts all with a value of 1 on an axis of 0 to 1. With row and column borders on, the result is a grid with a separate mark (bar) for each team, which I can control the colour of. Below is the view:
Using Colour to Highlight Selected Teams
To highlight those teams selected, i.e. those that are in the parameter, I created a calculation to check if the parameter contains the team name and return TRUE if it does or FALSE if it doesn’t. This was then put on the Colour shelf:
Automatically Deselecting the Selected Mark
Whenever you click on a mark in the view, Tableau highlights that mark and puts a border around it, which usually makes sense. That is unless, for UI purposes, you don’t want that to happen.
In this case, I want to be able to select a team and the only UI change I want to see is the bar for that team change colour. I don’t want the colour of other teams to be dimmed and I don’t want a border to show around the selected team’s bar.
This is how the view looks by default when a team is selected:
There are different approaches to achieving the desired result and Jonathan Drummey recently wrote a blog post that gives a lot of background. He also started a thread on twitter, which resulted in a various suggestions, including this one from Yuri Fal, which works very well, so I used it here.
I recommend taking a look at Yuri’s workbook which he links to in his tweet above. In summary, the approach involves passing a filter value from one dimension to another dimension, with the action setup with the source as the dashboard sheet and the destination as the underlying view:
With the filter action in place, the UI provides a more natural experience. You can also see how the tooltip changes, when nine marks have been selected:
Below is an image of the final visualisation. Click the image to open the workbook in Tableau Public:
Thanks for reading!