KNOWLEDGE BASE

Sorting Dimensions With Dynamic Measure Selection


Published: 28 Mar 2016
Last Modified Date: 13 May 2016

Question

How to sort dimension by a dynamic measure.

Environment

Tableau Desktop

Answer

The following instructions can be reviewed in the workbook attached below.

Step 1: Create a parameter

  1. Right-click in the parameter pane and select Create Parameter.
  2. From Data Type, select String.
  3. For Allowable values, select List
  4. Populate the value list with measure names (ex: "Sales", "Profit", etc.).
  5. Click OK.

Step 2: Create a calculated field to use for the sort:

  1. Navigate to Analysis > Create calculated field....
  2. Name the calculated field and enter a formula similar to the following:
    CASE [Parameter] 
    When "Sales" Then [Sales] 
    When "Profit" Then [Profit] 
    END
  3. Right-click on the parameter from Step 1 and select Show parameter control
  4. Right-click on the dimension to be sorted by selected measure, and select Sort....
  5. For Sort Order, select Descending.
  6. For Sort By, select Field.
  7. From the drop-down menu, select the parameter created in Step 1. 
Did this article resolve the issue?