You can easily sort your data by different dimensions when you use a parameter control. For example, you have several dimensions—Item, Category, Department, and Region—and you want to be able to select the dimension from a drop-down list by which to sort the data. To do this, complete the following tasks:
- Create a parameter with the dimension values you want to sort by and show the parameter control in the view.
- Create a calculated field used to perform the sort.
- Build the view.
Step 1: Create a parameter
- Open Tableau Desktop and connect to the Sample - Superstore data source.
- Right-click in the Data pane, and then select Create Parameter.
- In the Create Parameter dialog box, do the following:
- Name the parameter. For this example, name the parameter Sort By.
- For Data Type, select String.
- For Allowable values, select List.
- For Value, enter the following list of values: Department, Category, Item, and Region.
- Click OK.
- Right-click the parameter, and then select Show Parameter Control.
Step 2: Create a calculated field
- Select Analysis > Create Calculated Field.
- In the Calculated Field dialog box, do the following:
- Name the calculated field. For this example, name the calculated field Sort by Dimension.
- In the Formula text box, build the following calculation:
CASE [Sort By]
WHEN 'Department' THEN [Department]
WHEN 'Category' THEN [Category]
WHEN 'Item' THEN [Item]
WHEN 'Region' THEN [Region]
END
- Verify that the calculation is valid, and then click OK.
Step 3: Build a view
- Drag Item, Category, Department, and Country/Region to the Rows shelf.
- Drag Sales to the Columns shelf.
- Drag Sort by Dimension to Rows and then drop it in front of Item.
- Right-click Sort by Dimension on Rows, and then select Sort.
- For Sort order select Ascending, for Sort by select Alphabetic, and then click OK.
- Right-click Sort by Dimension on Rows, and then clear Show Header.
You can now use the Sort By parameter control to select the dimension you want to sort by.