## Consultant’s Diary: Nested LoD for Ranking

I’m going to try and share some of the techniques and methods I use as a consultant. Using Tableau & Alteryx daily means that I’ve found I take small techniques, tips & tricks for granted. Hopefully this will be useful for you all.

Table calculations can be mysterious.

When first learning about table calculations, it may be a tricky subject to wrap your head around. One of the most used table calculation is the RANK() function. Rank is a function which comes in many flavours…

A customer had a very specific question, which they mocked up in the trusty Sample Superstore dataset:

How can I Rank this by Technology (because it has the highest selling subcategory (phones)) – then Furniture – then Office Supplies?

A normal rank function calculates that Phones are the highest, but moving the Basic Rank to the left of Category will rank based on Sub-Category.

So the method I thought of getting around this was using a nested level of detail calculation. The idea behind this was I wanted to create a field which took the highest value/maximum sales value for each Subcategory within each Category.

So I wanted to keep the total sales for each Subcategory, but cascade the maximum value within each Category.

Based on Andy Kriebel’s excellent blog on understanding FIXED LoD calculations, we can translate my solution into plain English.

So with a { FIXED [Category] : MAX ( {INCLUDE [Sub-Category] : SUM([Sales])}) } we are saying…

For each Category, compute the Maximum total sales for each sub-category.

This means that Tableau will first compute and return the values of the SUM(Sales) for each sub-category, and then take the maximum value from this partition for each category.

The FIXED means that the value is returned per row within the category field. This then allows us to use this field with our RANK() table calculation.

Feel free to crack open the workbook above to look under the hood of this example.

London, UK

### 2 thoughts on “Consultant’s Diary: Nested LoD for Ranking”

1. Sunitha says:

we can also get it without using nested LOD
{FIXED [Category1]: SUM([Sales])} with Table Calculation Rank

1. Ravi Mistry says:

Nice one! I think the idea from the customer was to do this without a table calc. But thanks for sharing!

– Ravi