Knowledge Base

Nested Sorting

Product(s): Tableau Desktop, Tableau Public
Version(s): 8.1, 8.0, 7.0
Last Modified Date: 19 Jun 2014

Article Note: This article is no longer actively maintained by Tableau. We continue to make it available because the information is still valuable, but some steps may vary due to product changes.


Suppose you are looking at the sales categories for all regions. Have you noticed that if you sort the list of categories to show the highest sales at the top, the products are listed based on their total sales, across all regions?

In the view above, you can see that the Central region sells more products in the Telephones and Communications category than in the Chairs & Chairmats category, even though across all regions, Chairs & Chairmats category sell better. This kind of sorting is useful because you can see that although, as a whole, Chairs & Chairmats are selling better than products in the Telephones and Communications category, that is not the case in the Central region.

However, you may want to sort the products within each region instead. You can do that with nested sorting. Using the same example as above, you can now change it to a nested sort to see the categories listed in order of sales within each region. The first thing to do is create a combined field that has a row for all Region and Category field combinations.

Step 1

In the Dimensions pane, press the CTRL key, and then select the dimensions for which you want to compute the Top N. In this example, select the Region and Category fields.

Step 2

Do the following:

  • For Tableau Desktop8.0 and later, right-click one of the selected fields and select Combine Fields. The newly combined field, Category & Region, displays at the top of the Dimensions pane.
  • For Tableau Desktop7.0 and earlier, right-click one of the selected fields and select Create Set. In the Create Set From Selection dialog box, give the set a name, and then click OK. The new set displays in the Sets area of the Data window.

Step 3

Remove the Category field from the Rows shelf, and add the newly combined field to the Rows shelf.

Step 4

In the Rows shelf, right-click the Category & Region field and select Sort.

Step 5

In the Sort dialog box, define how you want to sort the products. In this case, select Descending order based on the Sales field aggregated as a Sum. When finished, click OK. Now instead of sorting the Category field, you sort the combined field

You'll see that now you have a nested sort where the categories are listed in order of sales within each region. The final view is shown below. You can see that Chairs & Chairmats are the third highest selling category in the Eastern region but in the West, Tables are the third best selling product.

Note: You may also want to change the formatting so that the row dividers are at the Region level instead of on every row. Select Format > Borders to open the Format window.

 

 

Alternate Search Terms: sorting, sort, top n, nested, sort inside a group
Did this article resolve the issue?

Attachments

Search Knowledge Base