Sets in Tableau are a powerful tool to create subsets of data based on certain conditions. This can add interactivity to your Tableau dashboards for your users through set actions. In this blog, we will go through a use case for sets in Tableau and the step-by-step process to achieve it in Tableau.

With sets, let’s create a dynamic chart for a dashboard using the Superstore data available in Tableau. This chart shows the total profit for each category and sub-category. We can drill down further by clicking on the category to view its sub-categories. This chart can be found on my Tableau public.

 

Step 1. Build out the chart

To start off, we will build out the chart in Tableau by dragging category and hitting the plus button to expand into the sub-category. We’ll then drag profit to the columns and ensure that the measure selected is SUM to find the total profit earned. The worksheet will look like this:

Step 2. Create a set

The next step is to create a set from category. To achieve this, we need to right click on category and select create set.

A new window will pop up to configure the settings for the new set. We will call this new set “Category Set” and leave all the categories unticked because we want them “out” of the set. This will make more sense in the next step.

We will drag the set into the column shelf to see whether something is in or out of the set. Since we didn’t tick any of the categories before, all the categories and sub-categories will be out of the set.

Step 3. Add set actions

Next, we want to add set actions. To do this, go to worksheet and select actions.

We will create a new set action by clicking on add action and selecting the change set values option. This allows us to update what is in or out of the set.

We will call this set action “Update sub-categories”. We’ll make sure our worksheet is selected and select assign values to set when we run the action and remove set values when we clear the selection.

We will then create a calculated field to add sub-categories when the set action is executed. To translate this into plain English, this calculated field means that when we select a category, show all the sub-categories for that category. Otherwise, show nothing (as indicated by the blank string).

Step 4. Creating the final chart

We will remove the category set and replace the existing sub-category with the calculated field we just made. The worksheet should look like this.

This chart can be formatted further by adding labels and colours. The final product can be viewed on my Tableau Public.

The Data School
Author: The Data School