Compare an Individual to a Group – Tableau Set Actions


Comparing an individual to a group is a common ask for Tableau developers.

Using Tableau sets and set actions enables the comparison of an individual to a dynamic group.

Or to compare a dynamic group with another dynamic group.

When would you want to compare an individual with a group?

Commercial examples of this comparison include:

  • comparing a salesperson with other salespeople
  • comparing a region with other regions
  • comparing a product with other products

Whatever the comparison, Tableau set actions have added significant flexibility.

How to compare an individual to a group in Tableau

To begin we can take a very simple example to compare an individual to a group. The example is comparing a country with some other countries.

There are multiple ways to do this.

Compare an individual to a group using a calculated field

The simplest way is to create a calculated field. In this example we compare the United Kingdom with the other counties in the Superstore data set.

Create a boolean calculated field:

[isUK]: [Country/Region]="United Kingdom"

Put that field to Colours and it will give the United Kingdom a different colour.

Tableau line chart with United Kingdom highlighted
Use a Boolean field to highlight the UK

Compare an individual to a group using a Set

Another and dynamic (since Tableau 2020.2 at least)  way to compare is using a set.

Create a set by right-clicking the country field and Create Set. Choose the United Kingdom and save it.

Tableau create a set and select the United Kingdom
Only add the UK to the Set

Similar to using a calculated field, put the set on the colour shelf and it colours the UK different to the other countries.

Since Tableau 2020.2 (perhaps slightly earlier but I’m not sure) it provides the option to Show Set.

This is identical in appearance to showing a filter.

Furthermore, this allows the user to select the items to be in and out of the set. Hence the set is now dynamic, allowing simple comparison.

Tableau line chart with UK highlighted and a set filter alongside
The Set contents is controlled by the filter

Compare an individual to a dynamic group using Set actions

Another alternative option is using Set Actions. These enable the user to, for example, click an item in a chart to alter the contents of the set.

In the below example, again comparing countries, there are 2 bar charts.

One shows the list of countries to compare with the group.

The other bar chart shows the list of countries in the comparing group.

2 tableau bar charts side by side for choosing comparing items
Clicking the bars either adds or removes items from the set

Click a bar in either chart and that country moves from one group to the other.

Very simple to compare a dynamic individual(s) with a dynamic group.

How to use Tableau set actions to compare with a dynamic group

Create a set on the country field, the same as the above Comparison Country set. Call the new set CompareItems.

Build the 2 bar charts, one is for In, the other for Out of the set.

Put the set on to Filters. On the “In” sheet, the Comparing List, “Show Members in Set”.

Alternatively “Show In/Out of Set” and choose In. On the “In” sheet it doesn’t matter.

Tableau bar chart with a set as a filter
The CompareItems set is only showing values in the set

However, on the “Out” sheet, the Comparator Group, it does matter.

The filter should “Show In/Out of Set” and be Out.

Using the set on the filter shelf to select out of the set
Choose Out to show those items not in the set

Put both sheets on the dashboard and set up the actions.

When a user clicks a bar in the In bar chart we want the item to move to the Out, and vice versa.

Create the Set Actions

We need two actions:

  1. To add an item to the Comparing List – i.e. add it to the set
  2. To remove an item from the Comparing List – i.e. remove it from the set
2 set actions listed in the Tableau action dialog box
One action adds to the set, the other removes from the set

To set up these actions click Dashboard – Actions.

The first action, to add to the Comparing List, will trigger when the user clicks an item in the Comparator Group. On click the item will move from the Comparators group to the Comparing List.

Therefore set up the action as follows:

  • Source Sheet is the Comparator Group
  • Run action from Select
  • Choose the relevant set – CompareItems for this example
  • Running the action will Add values to set
  • Clearing the selection will Keep set values
create a set action to add items to the set
Add items to the set on click of the bars

The next action will remove from the Comparing List. Very similar to the previous action, set it up as follows:

  • Source Sheet is the Comparing List
  • Run action from Select
  • Choose the relevant set
  • Running the action will Remove values to set
  • Clearing the selection will Keep set values
Create a set action to remove items from the set
Remove items from the set on click of the bars

The dynamic sets are now created to use as you wish.

In the example below there’s a line chart comparing the chosen country(s) – the Comparing List – with a group of other countries – the Comparator Group. The user can separate the Comparator Group into the individual countries or keep them as a group.

Want to master set actions in Tableau? Take this 2.5 hour online course, a Tableau Masterclass in Parameter and Set Actions.*

This grouping or separating is using a parameter and calculated fields. Download the workbook to explore that area of the dashboard.

*We may earn an affiliate commission if you purchase this course

Leave a Comment