KNOWLEDGE BASE

Creating a Parameter Control to Sort By Dimension


Published: 07 Dec 2016
Last Modified Date: 10 Sep 2017

Question

How to use a parameter to choose which dimension to sort your view by. 

Environment

Tableau Desktop

Answer

The below steps are based on Sample - Superstore data. 

Step 1: Create a parameter

  1. Right-click in the Data pane and select Create Parameter. 
  2. In the Create Parameter dialog, do the following, then click OK: 
    • Name: Sort By 
    • Data Type: String
    • Allowable Values: List
    • For Value, enter the following list: Category, Sub-Category, Product Name and Region.  
  3. Right-click the Sort By parameter and select Show Parameter Control. 

Step 2: Create a calculated field 

  1. Select Analysis > Create Calculated Field.
  2. Name the field Sort by Dimension, enter the following formula, then click OK:
    CASE [Sort By]
    WHEN 'Category' THEN [Category]
    WHEN 'Sub-Category' THEN [Sub-Category]
    WHEN 'Product Name' THEN [Product Name]
    WHEN 'Region' THEN [Region]
    END

Step 3: Build your view 

  1. Drag Product Name, Sub-Category, Category, and Region to Rows. 
  2. Drag Sales to Columns. 
  3. Drag Sort by Dimension to Rows, placing it to the  left of Product Name. 
  4. Right-click Sort By Dimension on Rows, and select Sort. Choose the following options, then click OK: 
    • Sort order: Ascending
    • Sort by: Alphabetic
  5. Right click Sort by Dimension on Rows, then un-check Show Header. 

You can now use the Sort By parameter control to select which dimension to sort by. 

Additional Information

To view these steps in action, see the video below: 
Did this article resolve the issue?