
It was Lorna’s turn to set the challenge this week, and she took the opportunity to ask us to use a new feature in Tableau v2021.1 – Quick LoDs (you’ll obviously need v2021.1 to use the functionality, but the LoDs can be created manually in earlier versions if need be).
This blog will focus on
- Creating the Sub-Category Average Sales by Category LoD using Quick LoDs
- Formatting the difference calculation
- Colouring the bars
- Text for Tooltip
- Putting it all together
The viz itself isn’t that complex once you’ve nailed the LoD, so lets’ start with that bit.
Creating the Sub-Category Average Sales by Category LoD using Quick LoDs
The what…? It’s a bit of a mouthful,.. the “Sub-Category Average Sales by Category”. What we’re essentially after here is the Total Sales per Category / No of Sub-Categories in the Category. To do this with LoDs, we first need to create an LoD to represent the total sales in each Sub-Category.
As mentioned in the requirements / referenced in the KB article above, you use a combination of ctrl/command click & drag to create an LoD via the Quick LoD feature. In this case I dragged the Sales measure onto the Sub-Category dimension, and this automatically created
Sales (Sub-Category)
{ FIXED [Sub-Category]: SUM([Sales]) }
which is the sales per sub-category.
From this, I then dragged this measure onto the Category dimension, which automatically then created
Sales (Sub-Category) (Category)
{ FIXED [Category]: SUM([Sales (Sub-Category)]) }
BUT I then edited this to change the aggregation to AVG, so the field became
{ FIXED [Category]: AVG([Sales (Sub-Category)]) }
This gives the average value required, which you can see is the same across the rows in a single Category :

Formatting the difference calculation
The viz displays the % difference between the Sub-Category sales and the average. This is calculated with
Difference
(SUM([Sales])- SUM([Sales (Sub-Category) (Category)])) / SUM([Sales (Sub-Category) (Category)])
This is then custom formatted as ▲0%;▼0% (I use this site to get my shapes from).
Colouring the bars
The bars need to be coloured based on the value of the Difference field, so another calculated field is required
Colour
[Difference]>0
This will just return true or false and can dropped on the Colour shelf of the bars.
Text for Tooltip
Within the tooltip, the % difference is displayed, along with some text which indicates if it is above or below the average. For this we need another calculated field to reference in the Tooltip.
Above | Below
IF [Difference]>0 THEN ‘Above’ ELSE ‘Below’ END
Putting it all together
With all the calculated fields built, the the chart itself is a relatively simple dual axis chart
- Add Category then Sub-Category to Rows
- Add Sales to Columns and sort descending
- Add Sales (Sub-Category) (Category) to Columns. Make dual axis and synchronise axis
- Click on the All marks card and remove Measure Names from the Colour shelf.
- Click on the Sales marks card and change mark type to bar; add the Colour field to the Colour shelf and adjust accordingly; add Difference to the Label shelf and format appropriately.
- Click on the Sales (Sub-Category) (Category) marks card and change mark type to Gantt; adjust the Size to be as large as possible; set the colour to the relevant grey.
- On the All marks card, add the Above | Below field to the Tooltip shelf, then edit the Tooltip on the All marks card to create the required text.
- Finally, remove axis, remove the column heading labels, remove grid lines and column borders and format the displayed text appropriately. Title the viz.

A very brief post today, but hopefully I’ve ticked off all the required elements, My published viz is here.
Happy vizzin’! Stay Safe!
Donna