After a long pause, let’s get back into the Tableau Hacks. In this one, we are going to have a look into multi-value parameters. It is one of those little pet peeves — parameters can only hold a single value at a time. You can do little tricks, like adding an “All” option to a list parameter, but nothing out of the box to be able to tick two or more options in a list parameter:
What if I tell you that you can have multi-value parameters with a bit of Tableau magic? We are going to build a view to act like a filter. And this filter-view is going to drive a string parameter with concatenated values. If you have seen my previous blogs, you will by now know that “concatenation is King” in these hacky-parameter tricks.
We will start with a map view again today, and this is what we will aim for:
First we’re going to make a group of Countries – loosely defined as Europe. I just dragged a circle around Europe and created the group. We will filter down to this group of countries only. Now we put [Country] itself on Details and change the view to a filled map.
Next, we drag [Country] to our view again and drop it in the top left corner to add an additional Marks layer:
Tableau will probably change that one to Circle marks, lets keep it that way. To this Circle mark layer, add SUM([Sales]) to both Colour and Size. The filled map layer will probably change to grey, which is fine again for now. Finally, let’s drop [Order Date] on the filter shelf and filter to the latest year 2019, and add [zzTrue] and [zzFalse] fields in there (contains just True and False as calculations) to the Details shelf for de-highlighting later (see blog no 5 for more info).
This view will look something like this:
Next up, we are going to make a forklift type crosstab view. The aim of the forklift is to combine multiple visuals into a single tabular format – as you can see in the initial image, we would like to have [Country], a radio button style circle to select and the SUM([Sales]) in a single view. If you would like to know more about a forklift in Tableau, please have a look at this blog.
First, place the same filters on the filter shelf as the ones on the Map view, so [Order Date] is set to 2019 and the “Europe” Country group. Next, add [Country] to the Rows shelf. Now we need to create a placeholder calculation – simply create a calculation called [Placeholder] just MIN(1) as calculation. Add the [Placeholder] to the Columns shelf 4 times and make the first two and last two dual axis. Your view will now look something like this:
Now we create a text parameter, [Country Parameter MultiSelect], that allows all values – this will be THE multi-value parameter. For testing and validation reason, make sure to leave a country (in Europe) in the Current value box.
We add this parameter to a boolean calculation called [Country Filter/HL], that will act as filter but also as a highlight function:
[Country Filter/HL] = CONTAINS([Country Parameter MultiSelect],[Country])
We also need a field that we can apply to the parameter when we click a Country. Simply using the existing [Country] field for that will not work very well, since we need a trick to also remove values from the parameter when we want to deselect it. Instead we create a field that will do the concatenation at calculation level and it will check if the countries that are clicked are already part of the Parameter, and remove them if needed:
[Country for Parameter] = IF CONTAINS([Country Parameter MultiSelect],[Country]) then REPLACE([Country Parameter MultiSelect], [Country]+’,’,”) else [Country Parameter MultiSelect]+ [Country]+’,’) end
A short translation of that calculation: If the [Country Parameter MultiSelect] parameter already contains the country I just selected, give me the value currently in the [Country Parameter MultiSelect] parameter excluding this country and the comma after. If the country is not already in the [Country Parameter MultiSelect], then give me the value of the [Country Parameter MultiSelect] parameter and add this country to the parameter, with a comma.
We add [Country Parameter MultiSelect] as well as the filter/highlight field [Country Filter/HL] to the view, change the first Placeholder to an open circle shape, the second placeholder to a circle mark (not shape) and put the [Country Filter/HL] on colour with True being any colour we’d like and False being white. Then we change our third placeholder to Text with SUM([Sales]) and the last placeholder can just be a polygon – this one is just there so we can add a label to the top of this column.
Remove the Axis ticks and titles from the bottom Axis. Remove the Axis ticks on the top axis and change the titles to something like “Selected” and “Sales.” Adjust the column width so that the SUM([Sales]) value fits comfortably and finally, add [zzTrue] and [zzFalse] to the detail shelf for All. The view should now look like this:
Quickly go back to the map view, and add the [Country Filter/HL] field to the colour shelf of the filled map layer and, if you want, you can also add the [Country for Parameter] field to make the parameter action work from both the Crosstab and the Map.
Now, put both views on an empty dashboard, giving the crosstab about 1/3 of the total width and the map the remainder. Add the parameter action to update the [Country Parameter MultiSelect]. Notice that the Aggregation is set to none, as the field we apply to the parameter [Country for Parameter] is doing the concatenation for us which enabled us to also deselect countries:
To complete this, we add two de-highlighting actions to the dashboard as well, one to the Crosstab and one the Map. Here we add a filter action which applies the [zzTrue] and [zzFalse] field originating from the one of the views on the dashboard and targeting the same view in isolation. This prevents the mark (Country) from being highlighted as Tableau regenerates the mark in a fraction of a second whilst attempting to filter false to true (which is impossible). Again, see blog number 5 in this series for more information:
Now for completeness, you might want to add a Reset button. Once again (I know, I am repeating myself), it’s probably best to have a look at blog 5, but here’s a really brief summary:
- Create a new sheet
- Add “Reset” as Text on the Text shelf
- Add [zzTrue], [zzFalse] and an “empty” calculation (just two single or double quotes in a calculated/ ad-hoc field – [Empty] = ‘’)
- Change background of this sheet to grey, change font to whatever you like
- Add to the dashboard, floating or tiled if you have a good spot
- Add the de-highlighting filter action to this “Reset” sheet
- Add the parameter action to apply the ‘empty’ field to the [Country Parameter MultiSelect] parameter to deselected all Countries in one go:
Here is the final result:
Check out the full dashboard for this blog post here:
https://public.tableau.com/views/TableauHacks/8_Multi-valueparameter