Set Actions
Use set actions to let your audience interact directly with a viz or dashboard to control aspects of their analysis. When someone selects marks in the view, set actions can change the values in a set. For examples on how set actions can be used, see Examples of set actions.
Set actions take an existing set and update the values contained in that set based on user actions in a viz. You can define the set action to include:
- the source sheet or sheets it applies to.
- the user behaviour that runs the action (hover, select or menu).
- the target set (the data source and set to be used).
- what happens when the selection is cleared.
To change or affect a visualisation, the set referenced in the action must be used somehow in the visualisation. You can do this in different ways, such as using the set in a calculated field that you then use to build the viz, or by placing the set in the view or on a Marks card property.
You can create set actions in Tableau Desktop, Tableau Cloud and Tableau Server. However, set actions can't be used with Stories.
General steps for set actions
Create one or more sets. The sets you create will be associated with the data source that is currently selected. For details on creating sets, see Create Sets.
Create a set action that uses one of the sets you created. You can create multiple set actions for different purposes.
Depending on the behaviour you want to make available to users for their analysis, you might want to create a calculated field that uses the set. For details on creating calculated fields, see Create a calculated field.
Build a visualisation that uses a set referenced by a set action. For example, if you create a calculated field that uses the set, build the view using that calculated field. Or, drag the set to Colour in the Marks card.
Test the set action and adjust its settings as needed to get the behaviour you want your audience to experience.
Getting Started: For an overview of what you need to know to create set actions, see On Your Marks, Get Set, Go: Everything You Need to Know to Get Started with Set Actions(Link opens in a new window) on the Data Viz Linds(Link opens in a new window) blog.
Create a set action
In a worksheet, select Worksheet >Actions. In a dashboard, select Dashboard >Actions.
In the Actions dialog box, click Add Action and then select Change Set Values.
In the Add/Edit Set Action dialog box, specify a meaningful name for the action.
Select a source sheet or data source. The current sheet is selected by default. If you select a data source or dashboard you can select individual sheets within it.
Select how users will run the action.
Hover - Runs when a user hovers the mouse cursor over a mark in the view.
Select - Runs when a user clicks a mark in the view. This option works well for set actions.
Menu - Runs when a user right-clicks (control-clicks on Mac) a selected mark in the view, then selects an option on the context menu.
Specify the target set. First, select the data source, and then select the set.
The sets available in the Target Set lists are determined by the data source that you select and the sets that you have created in the workbook that are associated with that data source.
In this example, the target set is using Global Superstore 2016 as the data source and High Delivery Cost Orders as the set.
Specify what happens when the action is run in the view:
Assign values to set – Replaces all values in the set with the values selected.
Add values to set – Adds individually selected values to the set.
Remove values from set – Removes individually selected values from the set.
Specify what happens when the selection is cleared in the view:
Keep set values - Current values in the set remain in the set.
Add all values to set - Adds all possible values to the set.
Remove all values from set - Removes previously selected values from the set.
Click OK to save your changes and return to the view.
Test the set action by interacting with the visualisation. Tweak some of the settings for the action to adjust the selection behaviour as needed.
Note: Selecting Add values to set or Remove values from set via the Set Action dialog modifies the values selected in the General tab of the set’s definition – just like Assign values to set does. This differs from the Add to and Remove from functionality available only in authoring mode via the set’s context menu in the tooltip. The latter unions or removes values to and from the set after the condition specified has been applied.
Examples of set actions
The following examples show just a few of the ways you can use set actions. To follow along, you will need to be familiar with creating and using sets and calculated fields. For details, see Create Sets and Create a calculated field.
Learn more: For additional in-depth examples of how you can use set actions demonstrated in Tableau, see:
- 8 ways to bring powerful new comparisons to viz audiences with set actions(Link opens in a new window) in the Tableau blog(Link opens in a new window)
- 8 analytic concepts to express with Tableau set actions(Link opens in a new window) (Tableau blog)
- Designing advanced analytics applications with Tableau set actions(Link opens in a new window) (Tableau blog)
- Topics on set actions on the Data Viz Linds(Link opens in a new window) blog
- Set action examples in the Art of the Vizable(Link opens in a new window) website by TabLabs.
Watch a video:
Proportional brushing
A classic use case for set actions is proportional brushing, described in How to do proportional highlighting with set actions(Link opens in a new window) on the Tableau blog(Link opens in a new window) and Tableau Set Actions(Link opens in a new window) from The Information Lab blog(Link opens in a new window) (along with other examples).
This example uses the Sample – Superstore data source. This set action changes the colour of existing marks in the view based on the proportion of the mark that is in or out of the set.
Connect to Sample - Superstore data in Tableau Desktop.
In a new sheet, drag the Sales measure to Columns, and drag the Segment dimension to Rows.
In another blank sheet, drag the Sales measure to Columns, and drag the Sub-Category dimension to Rows.
Create a set for the Segment dimension named Segment Set.
In the sheet that shows Sales by Sub-Category, drag Segment Set onto Colour in the Marks card.
Swap the colours used to show marks IN or OUT of the set.
Create a new dashboard. Drag both sheets into the dashboard.
On the Dashboard menu, select Actions. Click Add Action, and then select Change Set Values.
Configure the action using the same settings as shown in the image below.
Click OK to save your changes and return to the view.
Test the set action by clicking the marks for each segment.
Asymmetric drill down
Set actions can also be used across multiple sets for more complex interactions. If a data set has hierarchical information, such as Category, Sub-Category and Manufacturer, normally drilling down the hierarchy expands all values at a given level. However, you can use set actions for asymmetric drill down, opening only the next hierarchy level for the selected value.
This example uses the Sample – Superstore data source.
Set actions are used here in conjunction with two calculated fields to create an asymmetric drill down experience.
Create a set for the Category field named Category set.
Choose any category to be a member of that set. The membership is temporary and will be overwritten by the set action.
Create a calculated field named Asymmetric Sub-Category.
Right-click the Sub-Category field in the Data pane, and then select Create Calculated Field.
Type the following calculation:
IF [Category set] THEN [Sub-Category] ELSE [Category] END
If the category of the mark or marks in the view is in the Category Set, the calculation will return the Sub-categories for that Category. Otherwise, it will return the Category again.
The set isn't in use in the view yet and has no action associated with it, so it is static for the moment.
Build the view by dragging the Category and Asymmetric Sub-Category fields to Rows (in that order). Then Drag Sales to Text in the Marks card.
Create a set action.
On the Worksheet menu, select Actions. Click Add Action, and then select Change Set Values.
Name the action Asymmetric Drill to Sub-Category.
Select the following options:
- Source Sheets: Make sure the only the current sheet is selected.
- Run action on: Choose Select. This will make the action apply when the user selects a mark or marks in the view.
- Target Set: Select the current data source from the first drop-down list and the Category set from the second drop-down list.
- Clearing the selection: Select Remove all values from set.
Click OK to save your changes.
Test the set action.
When you click on a header or mark in the view, it will expand out to the next level. Clicking a category bar will expand its sub-categories.
Colour scaling
Colour values in a viz often can be distorted by outliers. When one country has a significantly higher value than other countries, the nuance of differences between those non-extreme values can be lost.
A set action can update the values in a Country set based on the selection in the viz. That set is then used in a calculated field that computes the value of the relevant measure for only countries in that set, and that calculated field is placed on colour. Now, when countries are selected in the map, the colour palette is based only on those countries, showing greater visual differences between those values.
This example uses the Global Superstore data source.
Create a set on the Country field named Country set. Chose any country to be a member of the set. The membership is temporary and will be overwritten by the set action.
Create a calculated field named Country Shipping Cost.
Right-click in the Data pane, and then select Create Calculated Field.
Type the following calculation:
IF [Country set] THEN ([Shipping Cost]) END
If the country of the mark(s) in the view is in the Country set, the calculation returns the Shipping Cost. Otherwise, it does nothing.
The calculated field ties the set into the view.
Double-click the Country dimension to automatically create a map.
Drag Country Shipping Cost to Colour in the Marks card. The map should automatically update to a filled map.
Create the set action: Country colour scaling.
On the Worksheet menu, select Actions. Click Add Action, and then select Change Set Values.
Name the action Country colour scaling.
Select the following options:
- Source Sheets: Select only the current sheet.
- Run action on: Choose Select. This will make the action apply when the user selects a mark or marks in the view.
- Target Set: Select the current data source from the first drop-down list and the Category set from the second drop-down list.
- Clearing the selection: Select Add all values to set.
Click OK to save your changes.
Test the set action.
When you select a mark or group of marks in the view, the colour palette responds by representing the values for those marks, not the entire data set.
Relative dates
This dashboard example contains multiple relative date calculations. Based on a target date, the dashboard displays the difference from the previous day, the percent change from the same month in the previous year, the Year to Date sales for the current year and Year to Date sales for the previous year.
The set action in this dashboard updates the target date and relevant date calculations in response to a user clicking a mark on a timeline.
This example uses the Global Superstore data source.
The set action in this example is applied to the Timeline sheet in the dashboard, and uses that sheet to drive the behaviour of the dashboard. When a user selects a mark in the Timeline view, the set action updates the Selected Date set with a single date value.
In this example:
A Selected Date set is built on the Order Date field.
An Update Target Date set action updates the Selected Date set so the date value for the mark selected in the view is the only value in the set.
A Target Date calculated field captures the date value from the Selected Date set, and that calculated field is referenced by other relative date calculations in the viz.
Each sheet in the dashboard uses calculated fields to update its displayed values.
Note: Because this example is more complex, the description below gives a summary of the major steps and settings involved, rather than specific details.
Timeline sheet settings
Sales is on Rows. A calculated field named Target Date is placed on Detail to make it available to the reference line.
Starting in Tableau 2020.2: The above image doesn't reflect the latest user interface. For each table or folder in the Data pane, a grey line separates dimensions (above line) and measures (below line). The Dimensions and Measures labels are no longer used in the Data pane.
Order Date is on Columns as Exact Date.
The reference line is applied to the Order Date field and is set to be the Minimum of Target Date.
A set action is applied to this sheet that updates the Selected Date set based on what mark is selected in the view.