KNOWLEDGE BASE

Dynamically Ranking Measures by Most Recent Data


Published: 20 Jan 2015
Last modified date: 20 Jul 2023

Question

How to dynamically sort and rank measures by creating calculated fields.

Environment

Tableau Desktop

Answer

The example below can be found in the attached workbook, which uses the example data source Superstore.
  1. Create a Calculated Field [LookupValue]

    LAST()

    What this does is Index the columns, so that the column on the far right is always 0

  2. Create a Calculated Field [Across_Value]

    WINDOW_SUM(IIF([LookupValue]=0,([Value]),0))

    What this does is check each column for the value of LAST(). If it is 0 (The last column), then we sum the Measure amount, else, we have 0.

  3. Create a Calculated Field [Rank]

    RANK([Across_Value])

    What this does is Rank the SUM of the column on the far right in Tableau.

    For the COMPUTE USING for RANK

    Rank > Table Down
    Across_Value > Table Across
    Lookup > Month Then place the [Rank] field on the worksheet on the far left as a discrete measure, and hide the header.

Did this article resolve the issue?