Today at work a Tableau challenge came up that I couldn’t overcome alone, but fortunately our Tableau support from The Information Lab means that we have access to a whole bunch of experts who deal incredibly quickly with random requests. Emma Whyte rode to the rescue in this instance.
Here’s the scenario:
- One colour to always identify a specific dimension member
- Sequential colouring on all other dimension members
Here’s how to do it. The first view is simply Sample – Superstore data, having used Show Me to create the Treemap when Sub-Category and Sales were selected:
Let’s say I always want Phones to be highlighted in red, and then the sequential blue colouring can be applied to all of the other Sub-Categories. How do you do that? First, you need a basic boolean to isolate Phones:
If you stick that directly onto Colour, it is handled as a Dimension and it also clears SUM(Sales) from Colour. As a Dimension, it is isolated as its own entity, rather than having a dependency on other dimension members. See how it is on its own on the right, and there’s a notable white gap between it and the other Sub-Categories?
To resolve this and reintroduce it to its Sub-Category friends, you just right-click it on the Colour card and convert it to an Attribute. I found the standard Tableau knowledge base article to define ATTR() best:
When the ATTR function is used, the field becomes dependent on the level of aggregation of another dimension. The field no longer exists as independent values and is now wrapped in an aggregation, and then turned into a measure.
Below you can see the effect of that dependency on the wider Dimension.
Good. One part done. How do we reintroduce that sequential colour scheme for the other Dimension members? Drag Sales to Detail***:
Now right-click it, and set it to Discrete. Why? Well if it’s Continuous and put on Colour, it will replace ATTR(Phones). If you set it to a Dimension, everything gets disaggregated and all sorts happens:
Final option is Discrete, and you can then convert the Mark type to Colour by using the little icon to the left of the field:
With that done, you more or less achieve the desired result:
Personally, I consider that graduated colour scale to be the wrong way round – I’d rather the higher value sales were shaded darker. That’s easy to fix – just shove a ‘-‘ in front of the SUM(Sales) calculation at the part marked with three red asterisks (***) above:
A sample of this technique can be downloaded here.
Emma Whyte set a #WorkoutWednesday challenge based on our Information Lab call. As usual, this resulted in people demonstrating more than one way to overcome an obstacle in Tableau, so here is an alternative way that Andy Kriebel approached the challenge. His blog and workbook can be found here.
The #WorkoutWednesday challenge this week included a more difficult element than the problem we faced at work, in that it contained a parameter to allow users to select the Sub-Category to highlight – whereas at work we always wanted a specific dimension member to be highlighted. Parameters are basis things so I won’t focus on that, but here’s the Colour calculation:
It makes sense and is effective, but doesn’t quite match the brief as the depth of that orange varies depending on the Sub-Category selected.