Analytics tricks — Sorting by dimension using parameters using Tableau
How does one sort a view by more than one dimension/measure in Tableau? The following steps will help you accomplish this :
Consider the following Sales Data
shop_name category product price Reliance Food OAT 100 Reliance Digital Electronics Laptop 25000 Croma Electronics Speaker 700 Reliance House Hold Mob 150
- Right Click in Data Pane and select Create Parameter
- Dialogue Box will appear. Select the following and then click OK
- Name : Sort By
- Data Type : String
- Allowable Values : List
- In the list enter : Shop Name, Product, Category
- Right Click on the parameter create and select “Show Parameter Control”
Create Calculated field for Sorting -
- Right Click in Data Pane and select Create Calculated Field
- Type the following formula and type the name as sort_by_dimension and then click OK.
- if [Sort By] = ‘Shop Name’ then [shop_name]
- elseif [Sort By] = ‘Product’ then [product]
- elseif [Sort By] = ‘category’ then [category] end
Implement in View -
- Drag the required dimensions to row — In this case it could be Shop Name, Product, Category.
- Add measures like quantity, sales to column
- Drag sort_by_dimension to Row — placing it at left most
- Right Click on sort_by_dimension and fill in the following values on the dialogue box -
- Sort order : Ascending
- Sort by : Alphabetic
- Right click on sort_by_dimension and then un-check Show Header
Now, change in values of parameter will change the sorting order.
By Monu Agarwal
Originally published at .