KNOWLEDGE BASE

Creating a Parameter Control to Sort By Dimension


Published: 07 Dec 2016
Last modified date: 20 Jul 2023

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. 
 
CLICK TO EXPAND SOLUTION

Parameter, Calculation and View creations step

To view the steps showed in the below video, please expand the above section. Note: the video has no sound.

Additional information

Dimensions on the Rows or Columns shelf are treated hierarchically, so sorting on a dimension will not affect any dimensions left of it on the shelf.

If you want to mix data types or add an 'Ascending or Descending' parameter to the sort, a RANK() can be added to any non-number fields. See the attached "Sorting by ANYTHING" workbook.

Use a calculation similar to the following instead of the calculation in the above instructions:

IF [Ascending/Descending]='Ascending' then 1 else -1 END
*
IF [Sort by]='Category' then -rank(min([Category]))
elseif [Sort by]='Sub-Category' then -rank(min([Sub-Category]))
elseif [Sort by]='Sales' then SUM([Sales])
elseif [Sort by]='Profit' then SUM([Profit])
END

RANK() can be used on any data type to convert it to a number and retain the original order. For 'Descending', the entire calculation can be multiplied by -1.
Did this article resolve the issue?