Going the Distance in Tableau: Taking the Next Step with Set Actions


Going the Distance in Tableau: Taking the Next Step with Set Actions

In this series, we will explore different types of calculations involving calculating distance. From a simple iteration to geographic clustering, we will take your data as far as it can go with Tableau.

Adding onto the previous post about increasing our interactivity and boosting the dynamism of our data, we’re now going to discuss how set actions can take you even further in Tableau.

Set Actions Take You the Extra Mile

With the additional functionality of set actions in Tableau 2018.3 and beyond, we can make our map even more interactive by allowing users to simply click a city on the map and have our calculation recalculate instead of selecting from a parameter on the side of view. The calculations are all very similar with the exception that now the city is selected by a dynamic set.

To start off, create a set from the geographic field you are using; here, I am using City, State. It does not matter what selection you make here—this is simply a placeholder for now. Bring this set into the view (I placed it on Detail):

editing a set in Tableau

Now, we need to set up a variation of our City, State Indicator field that is used to order the cities in the temporary table. Sets operate as boolean values, either true or false, IN or OUT of the set. The syntax when sets are used in calculated fields can say if SET to mean if SET=true or, in our case, “if a city is in the set.” So our calculation will look like this:

calculated fields in Tableau

Creating the Set Action

Let’s implement the set action. If you plan to use this sheet in a dashboard, this will be set up as a dashboard action once in the dashboard, but we can also do it as a worksheet action, which is what I have done here. Go to Worksheet > Actions then Add Action > Change Set Values:

creating a set action in Tableau

Set actions allow us to dynamically change what values are in the set based off of an interaction with the visualization. In this case, we will run our action on Select, so when our user clicks a point on the map, that point will be in the set. The target set we want to use is the set based off of the geographic field: in this case s.selected city. I am going to Keep set values when the selection is cleared, meaning that if I select Bergen in Norway and then unselect it, it will remain in the set until I select another point:

distance calculations in Tableau

Now we can have a copy of the table calculation we used in the last example (see below) and run it against the selected city:

3959 * ACOS


SIN(RADIANS(LOOKUP(AVG([lat]), First()))) * SIN(RADIANS(AVG([lat])))

+COS(RADIANS(LOOKUP(AVG([lat]), First()))) * COS(RADIANS(AVG([lat])))

* COS(RADIANS(AVG([long])) - RADIANS(LOOKUP(AVG([long]), First())))


table calculations in Tableau

We need to include the set and City, State in the Specific Dimensions and use a Custom Sort on City Indicator (set). This custom sort will cause our selected city—which was assigned the value 1—to rise into the top row of the temporary table, while all other cities—assigned the value 2—will fall below the first row.

Here is how the table calculation works with the set action, both on the map and behind the scenes in the temporary table:

distance calculations in Tableau

Keep following this series, and catch the next post about making dynamic comparisons and analyzing distribution centers!

More About the Author

Grant Eisenmenger

Analytics Consultant
Options for Row-Level Security in Tableau Now that you know you need Row-Level Security (RLS) and you are familiar with the basic concepts and building blocks, we can take a ...
Row-Level Security Basics in Tableau In this blog, we will run through fundamental concepts and building blocks for Row-Level Security (RLS) solutions. This will include: ...

See more from this author →

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK


Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072


Love our blog? You should see our emails. Sign up for our newsletter!