In Tableau version 2018.3 Set Actions were released. This feature was not really being clamored for, its release came without much hoopla, and at first people really didn’t know what to do with it….until it became one of the most popular release features of all Tableau time. Most users, myself included, did not regularly use sets while using Tableau, but the ability to dynamically edit the contents of a Set made the feature invaluable. If you haven’t already checked out www.artofthevizable.comor www.lindseypoulter.com, both wesbites are Set Action gold mines.
In December 2018 I published a viz on Tableau Public focused on segregation of public schools that utilized Set Actions. Within the viz you are able to click on a state which then drills down to the county level. Once you are at the county level, I utilized a relatively newer feature of Tableau, the viz-in-tooltip, to allow visibility into the individual school level by hovering on the desired county. This geographic drill down ability is the topic of today’s blog post.
If you want to follow along with your own data set you will need the have at least two geographic fields, in this data set they are State and County.
First, we want to make sure we understand what the Set function does. Before Tableau 2018.3, creating a Set meant defining a static grouping of a dimension that you were able to use to filter, highlight, or separate with the Set field operating much like a dimension field. The values you select for the Set were In, and the ones not selected to the set were Out. With 2018.3 you are now able to change which values are included in that Set via dashboard actions.
Before we get into creating our sets we will want to create a State field that read as a string. This way you will be able to still refer to the State name even when the geographical field is filtered out.
Duplicate your state field and then right click on the copy version and set as String (bottom of image to right). Now it is time to create our first Set. Right click on your newly created State STRING and Create -> Set. Click None. This allows for our Set to be blank before we identify what values we want included.
Now that we have our State STRING set, we need to create some logic for what values to show when States are selected to be In our Set. I will call this view, “Geo View.” Make sure the geographic role is set to County.
What this Set and calculated field are doing for us is saying that if a state is in the Set, that the Geo View will then produce the field [County]. When we create a Dashboard Action this will give us the ability to click on a State and without doing anything else, the Counties will populate.
In order for the rest of the states to disappear when clicking a State, we need to create another Set. Create this set from the same State STRING field then click All for the Set members. Also, create a State modified field like below. This formula says if the State we select is in the set (which it will be), then show NULL. If not, then show States. This will allow for us to go back and forth between drilling down into counties then zooming back out to states.
Now we are ready to start building our viz. Since we will have two layers to this viz we will need to utilize a dual axis. Start first by dragging Geo View and State to your marks card. Your latitude and should populate automatically, just make sure to choose the filled map for your map display.
Create a dual axis and then bring in the fields State Modified and State String to the second layer of the map. This will also need to be a filled map. At this point you should have a map similar to the one above. Make sure to add the second State Set to the filter bar to make sure our non-selected state will disappear.
Now for the Set Actions!
Create a new Dashboard in your workbook and drag in your map worksheet. Go to Dashboard -> Actions -> create Set Action. Our first set will be the one that allows for counties to pop up. So on our Section Action 1, make sure you run action on Select, then choose the correct data source and the first Set we created. When we clear the selection for our Set we actually want to Remove all values from the Set so that the Geo View field is no longer showing County. Our Section Action 2 will also run on select but we will Add all the values to the set when we clear the selection so that our map returns to all values showing.
Click on a State! The image below should appear. By selecting this State to the first Set we have displayed Counties, and the Geo View field is populating those counties for us. To get back to the State view, click on a county, then click off. This will reset your view and Add all the State values to the Set. You are now able to zoom in and out of states and county granularity.
If you want to go one level deeper, you will need to make sure your data set has Latitude and Longitude. Create a map worksheet that has individual points on the map. Then use your viz-in-tooltip feature to add that individual point map to the tooltip. This will allow you visibility from the county to the school (in this case).
If you have any questions or comments on this topic or approach make sure to email me at firstname.lastname@example.org
Credit to Jeff Shaffer @HighVizAbility for helping me on this viz and showing me this Set Actions concept originally.