Set Action and Parameter action to compare or drill down into a map

This post should have published last autumn but I could finish it, I will not even try to give any excuses. :)

Since last year, when set actions have been released, I enjoyed this feature so much that it becomes my favorite and I always used it in my Tableau Public dashboards or at work, in a way or another. If you read my posts, you know that I wrote about it a lot, but I noticed that I never wrote about one of my favorite use case : compare two categories or two countries. Here is an exemple I did for an Ironviz, but I used it at work a lot to compare dimension and give control to the end user.

Visualisation in Tableau Public:  link


Use Set actions to compare :



The idea was to be able to select a country by clicking on a viz and that the selected country change color. I wanted to always have the US Graph in red and visible and be able to color the country selected but coloring always the canada in the green-blue color for Canada and any other country should be white if not selected and deep blue otherwise.

To achieve that you need to create a set on the country field called [country to highlight] and a colouring calculation to color the selection as you please :

Coloring set :
if [Country / territory of asylum/residence]="United States of America" then 2
ELSEIF [country to highlight] and [Country / territory of asylum/residence]="Canada" then 1
ELSEIF [country to highlight] then 3
else 0
END

Then you can drop this coloring set into color on every worksheet you want and choose the color accordingly : 2 for red, 1 for green-blue, 3 for deep blue and 0 for white.

To make the selection dynamic you need to create a set action on the dashboard  ( go to dashboard/Action and select set action)

source : select the worksheet you want to click on, in my case the bars on the top right
target : set [country to highlight]
keep set value

So now if you click on France for instance, Canada will disappear and France will appear in blue :


If you want to maintain Canada, you just have to change the formula below, as something like :

if [Country / territory of asylum/residence]="United States of America" then 2
ELSEIF [Country / territory of asylum/residence]="Canada" then 1
ELSEIF [country to highlight] then 3
else 0
END

Of course you can refine this idea by having an interactive the title and comments by creating an additional field and use it on the title as for instance :

Title  :
if [country to highlight] then [Country / territory of asylum/residence]
else ""
END


Another way to do it is to use clearer selector the one I used on "which animal will kill you? " viz
(explanation in a previous post here)


Use Parameter actions to compare :

You can also do something like that where the dots are colored and will also served as a color legend. My idea here was to drive the users's attention into some countries data.


The dotted view is done by selecting :

mark : circle
row : attr(1)
column : country
color : select a distinct color for each country in your selection.

Note that this view is only working if you have 3-5 countries otherwise it is too confusing.

 
1. you create a parameter " country to highlight" based on the country field
2. you create a calculation to highlight differently the country depending if it is Iran, Turkey or US.

if [US?] then 1
ELSEIF [country to highlight]=[Country Of Residence]
and [country to highlight]="Turkey" then 2
ELSEIF [country to highlight]=[Country Of Residence] then 3
else 0
END

3. you place this calculation into color and color accordingly blue for Iran (3), purple for Turkey (2).
Here there is not other possibility because the dotted view, who has only 3 countries is triggering the view.

4. You create a parameter action, with the dotted view as a source, the target being the parameter " country to highlight" and the value : country.

5. to be able to annote the selected view, there is some subtility as you can discover when you download the view. But I create a dual axis where the three selectable countries are annoted on one of the view, whereas the other view displayed the maximum value ( here pakistan). I went to such complication because originally the view was  planned to be used with a region filter. Now I could probably simplify it with an annotation for Pakistan and the calculated field for annotate Iran Turkey or US.

As the view display the running sum of the number of Refugees depending of the selection and the US, this calculation is working:
RUNNING_SUM(SUM(if [set for colour US and highlight]>0 then [nb Refugees] END))

US will be always displayed because it is 1, if  Turkey is selected it will be displayed otherwise it will be Iran.


Use Set actions to drill down :

I did some example in the past of drilling down into a hierarchy or in a specific decade using set action (cf blog : here) but the idea here was to be able to display the detail of a specific region when clicking on a flow map.

At the beginning the map shows the refugees flows by regions


But once a region is selected you can see the detail per country, as it is difficult to indentify clearly the country ( I am not very good at geography), I added a text to display the top 4 countries and value.


1. Create a set on the region [set region]

2. Add a calculated field on filter :
filtering set
[set region]
and keep only the true value

3. The trick is to have the details of the view either as region or as country. so you need to add into details
a calculated field
[region or country]
if { FIXED :COUNTD([region origin])}>1
then  [region origin] else [Origin] END

This field will displayed the region if none selection is done and it will displayed the country otherwise.

4. You need to create a set action on the dashboard with the following characteristics :
- source : the map
- target  [set region]
- add all values to the selection

5. To fix the label you need to create a calculation
country or region name
IF [rank refugees]> 4  then "" else ATTR([region or country]) END

country or region value
IF [rank refugees]<=4 then SUM([nb refugees]) END


I hope I convinced you to use more set actions and parameter actions !