TABLEAU: Dynamic Tooltips using Table Calculations and Set Actions

by Seffana Mohamed-Ajaz

A recent feature that has been released in Tableau is Set Actions which allows users to drill down their data investigation while maximising the space the chart is using.

I love this new feature, however the calculations used to set up Set Actions show up in my tooltips, and I would like that calculation to only show up when the Set Action has been ‘activated’, if you will, and to disappear when the Set Action has been ‘deactivated’.

I will show you a step-by-step guide on how to make this possible by making a dynamic tooltip and using table calculations.

First, let’s build a chart

1) For this tutorial, I will be using Tableau’s Sample EU Superstore data.

2) Build a bar chart with Sales in the Columns shelf and Country in the Rows shelf, sort descending. To make things a little easier to read, add the Sales field onto the Label card in the Marks pane.

Figure 1: Chart showing sum of Sales in each EU country in descending order.

Second, create a Set Action

Let’s say that I would like to see sales in each Segment for each country. In other words, when I select a Country, my chart will drill down and show the Segment Sales for that Country.

3) To build this Set Action, I would first need to create a Set from the Country field.

Figure 2: Create a set from the Country field in the Dimensions pane.

4) Create a calculated field that would later be used to drill down from the Country-level Sales. I used an IIF calculation, this works the same as doing a normal IF statement.

Figure 3: Calculated field made for Set made in Figure 2 using an IIF calculation.

Translating what the IIF calculation in Figure 3 is essentially doing:

IF [Selected Country Set] THEN [Segment] ELSE ” END

5) Drag the Drill down from Country calculated field onto the Rows shelf, in front of the Country field.

6) Now we need to enable the Set Action. Go to Actions in the Worksheet settings in Tableau. On Add Action, select Change Set Values.

7) As seen in Figure 4, your Source Sheet should be the worksheet that you’re using the Set Action from. The Target Set will be Set that you created from the Country field in step 3. The Run Action should be on Select and the Clearing the Section will: should be on Remove all values from set.

Figure 4: Configuring Set Action for the worksheet.

8) If you click on a country the chart should drill down to show the sales of the Segments for that country.

Figure 5: Set Action shows the Sales value for each Segment in Italy.

Lastly, make the tooltip dynamic

You’ll notice when you hover over the bars when not drilling down that the Drill down from Country calculated field shows up in the tooltip but has vacant values. When you drill to a country, then the field in the tooltip will show which Segment it belongs to.

I am not a fan of how it flips from vacant and then non-vacant when the set action is enabled. Admittedly, I could just erase that calculated field from the tooltip, but I really want to see it when I have the set action enabled, so erasing it won’t help.

Figure 6: Tooltip vacant for calculated field when not drilled down as opposed to how it looks when it is drilled down.

9) Create a calculated field as follows in Figure 7.

Figure 7: This calculated field will be used in the chart tooltip and uses a table calculation function, WINDOW_MAX.

Explaining the calculation

This calculation is essentially saying:

Within the view, when the [Selected Country Set] set and [Drill down from Country] field is not equal to nothing in the view; in other words, both the set and the calculated field are enabled, then return the following sentence. If that condition is not met then return nothing.

The sentence being: [Segment] in [Country] has accumulated sales of £[Sales].

The FIXED calculation in Figure 7 is returning the Sum of Sales for each Country and each Segment.

To learn more about FLOOR calculations then read Eliott Sacau’s (DS7) blog.

10) Drag the Sales Tooltip calculated field onto the Tooltip card in the Marks pane.

Figure 8: Sales Tooltip calculated added to the view.

11) Edit the Table Calculation by right-clicking on the blue Sales Tooltip field in the Marks pane and select Edit Table Calculation.

12) On Specific Dimension, uncheck both Country and Drill down from Country fields. This will make the table calculation calculate the Sales for each Country and each Segment, as seen highlighted yellow in Figure 9.

Figure 9: Unchecking both the Country field and the Drill down from Country field in Specific Dimensions in Table Calculation configuration.

To learn more about the way Table Calculation operate in Tableau, check out Tableau Zen Master, Andy Kriebel’s, blog.

10) Edit the tooltip, erase all the default entry, and then insert the Sales Tooltip field into the tooltip.

Figure 10: Insert the Sales Tooltip field into the Tooltip.

Result

Now the dynamic tooltip should work! When the view has no drill down any particular country, hovering on the bars should do nothing tooltip-wise. When the view has been drilled down upon selecting a country, hovering on drilled down bars should show the tooltip calculated in step 9.

You can see this working in the video below.

Tooltip vacant when a country is drilled down. It is only after drilling down on a country that the tooltip will appear.

I have posted a similar blog to do with Dynamic Chart titles if you’d like to explore more options.

I hope that was useful! Leave a comment if you have any questions about the steps in this technical blog.

Avatar

Seffana Mohamed-Ajaz

Fri 01 Mar 2019

Thu 28 Feb 2019

Wed 27 Feb 2019

Tue 26 Feb 2019