
Erica set the challenge this week, which involved building the same visualisation in two ways – one using Table Calcs only and one using LODs.
To test the functionality and validate what’s going, I’m going to build the data out in a tabular format first.
The Table Calc Table
On a new sheet add Region and Category to Rows and Sales to Text. Sort by Sales descending. Then add Region and Segment to Filter, selecting all options, and show the filters.

Create a new field
Total Sales
TOTAL(SUM([Sales]))
and add into the table. This won’t be used later, but I’ve created so you can see the filtering behaviour.
This is a table calculation, and, by default when added to the table, it shows the total of all the rows against each row. We want to display the total per Region, so every row for a specific region shows the total of that region only. Adjust the table calc setting so it is computing by Category only.

Create a new field
TC – % of Sales
SUM([Sales]) / TOTAL(SUM([Sales]))
format to be % with 1dp and add into the table. By default it should have inherited the table calc settings we just applied for Total Sales, but if not apply the same settings, so it is computing by Category only.

If you do the maths taking the value in the Sales column and dividing by the value in the Total Sales column, you should be able to validate the result.
And if you test by adjusting the Segment and Region filters, everything should work as expected :
Filter out a Segment and the Sales and Total Sales adjust to exclude the value and the TC – % of Sales for a Region still totals 100%

Filter out a Region and that whole block is removed, but the values for all the other rows remain unchanged.

Now add Category to Filter and show the filter. Filter out a Category, and what we now see is the Total Sales now just reflects the total for the selected categories, and the TC – % of Sales still totals 100%. This isn’t the requirement. The % of Sales needs to calculate over all Categories regardless if it is excluded in the display.

To handle this, we create
TC – Filter Category
LOOKUP(MIN([Category]),0)
This is using a table calculation to basically return the value of the Category associated to the current row, which is basically looking up itself. However, as this is a table calculation, when added to the Filter shelf, it applies the filter after other computations (this is Tableau’s order of operations’), whereas the ‘quick filter’ applied above, is filtering the data first before then computing the total sales.
Remove Category from the Filter shelf, and add TC – Filter Category to the Filter shelf instead, selecting all options and showing the filter on the view. By default the table calc setting is set to table down which is fine – it is computing by both Region and Category. Now if you exclude a Category, the relevant rows disappear, but the Total Sales and therefore TC – % of Sales values remain unchanged.

The Table Calc Viz
The simplest way to build this (IMO) is to duplicate the table sheet then
- Remove Total Sales and Sales
- Move TC – % of Sales to Columns
- Show mark labels
- Adjust colour of bar
- Adjust colour of worksheet background
- Widen each row slightly
- Make the width of bars slightly smaller
- Edit title of % of Sales axis
- Adjust fonts of label headers and bar label and axis labels (I set to 8pt)

The LOD Table
Let;s repeat this now using LODs instead.
On a new sheet, once again add Region and Category to Rows and Sales to Text. Add Region and Segment to Filter and show the filter options.
Create a field
LOD – Sales per Region and Segment
{FIXED [Region], [Segment]:SUM([Sales])}
Add into the table. With all segments selected, we can see the total sales for each Region listed

and filtering out a Segment, the totals adjust as required.

If we now add Category to Filter, show the options and filter one out, the totals now no longer change, as the LOD – Sales per Region and Segment doesn’t include Category in its definition – its FIXED to just account for changes to Region and Segment.

So we can now create
LOD – % of Sales
SUM([Sales]) / SUM([LOD – Sales per Region & Segment])
and format to % with 1dp and add into table to validate.

You can now apply similar steps to those detailed above to recreate the bar chart viz for this data.

And once done, add both charts onto a dashboard with their relevant filters.
My published viz is here.
Happy vizzin’!
Donna





















































































































