MIP Logo

Nested Sort in Tableau with Rank Table Calculation

This post was originally published on The Data School blog between 2018 and July 2025, before our program was renamed to MIP’s Analytics Career Accelerator. References throughout this article to “The Data School” or “DS” all refer to what is now MIP’s Analytics Career Accelerator. The program, its people, and its commitment to launching outstanding analytics careers remain the same – just under a new name.

If you are having trouble viewing this article, please report it here

Sorting the measures is an important step in building a vizualisation as it helps us digest the data on display quicker.  Nested sorting is required when there is more than one dimension in the view.

I’m using superstore data set for this exercise, I want to find the top 10 product that generate the most profit in each region. To build the visualisation I dragged the Region and Product Name to Rows in that order and Profit to columns.  I dragged Product Name to Filters to get the top 10 products.

As you can see in the figure above, we are not showing the top 10 product names in each region.  To fix this we are going to use the rank table calculation.

Drag Profit to Detail on Marks card, right click to add a Quick Table Calculation and select Rank. Right click again to select Edit Table Calculation, in the Table Calculation window that pops up select Pane (down).

Right click Profit in Marks cards and convert it to discrete, the pill colour will change from green to blue.

Drag this blue pill to Rows and drop it between Region and Product Name.  You should see a header for Rank appear in the view.

I removed the product name filter that I had in the view before and pressed control and dragged the discrete (blue) Profit pill in rows to Filters.

Select 1 -10 for top 10 and click ok. You will now see the top 10 product names per region.  Clean up the view by right clicking on the discrete (blue) profit pill in rows and untick show header.

Right click and select format to clean up the row and column divider lines.

I use nested sorting quite often in my visualisations.  I hope this is useful.

 

Share this post