KNOWLEDGE BASE

Calculating Rank At a Level Other Than the Highest Level of Granularity


Published: 23 Mar 2016
Last Modified Date: 08 Sep 2016

Issue

How to calculate rank for a dimension on the Rows shelf that is not the last dimension.

Environment

  • Tableau Desktop

Resolution

The following instructions can be reviewed in the attached workbook.
  1. Create a calculated field with a name like "Sales per Sub-Category" with a calculation similar to the following:
    { EXCLUDE [State] : SUM( [Sales] ) }
  2. Create a calculated field with a name like "RANK_DENSE + LOD" with a calculation similar to the following:
    RANK_DENSE( SUM( [Sales per Sub-Category] ) )
  3. Drag [RANK_DENSE + LOD] to the Measure Values card.
  4. Right-click [RANK_DENSE + LOD] and select Edit Table Calculation…
  5. In the Table Calculation dialog, for Compute using, select Advanced…
  6. In the Advanced dialog, move each field from Partitioning to Addressing so that the fields are in the same order in Addressing as on the Rows shelf. In this example, the order should be: Region, Category, Sub-Category (group), State
  7. Click OK to close the Advanced dialog
    • Optional: Select the desired dimension for Restarting every.
  8. Click OK to close the Table Calculation dialog

Cause

RANK() cannot ignore a field in the view and therefore will always be calculated by the lowest level of granularity. Using an LOD expression to aggregate the values that are being used to create the rank up to the desired level, Tableau Desktop calculates the same rank for every within the desired level.
Did this article resolve the issue?