Was this page helpful?
Yes No

Sort Data in a Visualization

There are many ways to sort data in a visualization in Tableau. This article demonstrates all the ways to sort data in a visualization.

Sort data on an axis

A quick way to sort data is to use the sort buttons on an axis. To do so:

  1. In a worksheet, hover over a viz axis.

  2. Click the sort icon that appears.

    One click sorts the data in ascending order. Two clicks sorts it in descending order. Three clicks clears the sort.

The sort will update correctly if the underlying data changes.

Sort specific fields in the viz

To sort a specific field in the visualization:

  1. In a worksheet, right-click (control-click on Mac) the field you want to sort and select Sort.

    Note: You can only sort dimensions.

  2. In the Sort dialog box that opens, do the following:

    • For Sort order, select one of the following options:

      • Ascending - sorts the data in ascending order from lowest to highest or least to most.

      • Descending - sorts the data in descending order from highest to lowest or most to least.

    • For Sort by, select one of the following options:
      • Data source order - the order that the data source naturally orders the data. Generally for relational data sources, this tends to be in alphabetical order—more specifically, in natural sort order, which is identical to alphabetical order, except that multi-digit numbers are ordered as a single character. So, for example, in alphabetical sorting, "z11" comes before "z2" because "1" is evaluated as being smaller than "2", whereas in natural sorting "z2" comes before "z11" because "2" is evaluated as being smaller than "11".

        If you are using a cube, this order is the defined hierarchal order of the members within a dimension.

      • Alphabetic - sorts the data alphabetically.

        Note: This sort is case sensitive. It will sort [A-Z] before [a-z].

        To create a non-case sensitive sort, create a calculated field using the UPPER() or LOWER() functions to transform your strings into a consistent case. For more information, see String Functions.

      • Field - sorts the data based on values in another field. For example, you can select to sort by the Sales field, using the average aggregation.

      • Manual - allows you to manually sort the data in the order you prefer. For example, if you want to sort high school years in order: Freshman, Sophomore, Junior, Senior.

  3. When finished, click OK.

    The visualization updates with the new sorting.

You should keep the following rules in mind when interpreting the sort results:

  • Tableau computes the sort across the entire table using the specified criteria. See Sort Data in a Visualization for more information.

  • Sorts do not break the dimension hierarchy. Sorted fields are always displayed within the ordered context already set forth by the fields on the Rows and Columns shelves. This means that Tableau will not rearrange any of the headers of the fields that appear before (to the left of) the sorted field.

    If you want to break the dimension hierarchy when sorting a multidimensional data source, place only the hierarchy level that you want sorted on the Rows or Columns shelf.

Sort data using the toolbar

You can quickly sort data in ascending or descending order using the toolbar. To do so:

  • In a worksheet, on the toolbar located just above the Columns shelf, click the Descending sort icon to sort data from highest/most to lowest/least, or the Ascending icon to sort data from lowest/least to highest/most.

Sort data using headers or legends

You can manually sort data in your visualization by dragging and dropping members in a header or legend, such as a color or shape legend.

To manually sort data using a header:

  • In a worksheet, select a member in a header and drag it up or down.

    The viz updates with the new sort.

To manually sort data using a legend:

  • In a worksheet, select a member in a legend and drag it up or down.

    The viz updates with the new sort. Notice that the order the data points in the view appear also updated.

Create a nested sort

With the release of Tableau Desktop 2018.2, you can now create a nested sort without any additional calculated fields or combined dimensions.

Suppose you are looking at sales sub-categories for all regions in your country. In the view below, you can see that the Central region sells more products in the Chairs subcategory than any other subcategory. However it's harder to compare how Chairs ranked in other regions.

To see which subcategories ranked the highest in each region, you might want to sort the subcategories within each region instead. You can do this with nested sorting.

Set up the view

  1. In Tableau Desktop, open a new workbook and connect to the Sample Superstore data source that comes with Tableau.

  2. Navigate to a new worksheet.

  3. From Measures, drag Sales to the Columns shelf.

  4. From Dimensions, drag Region to the Rows shelf.

  5. From Dimensions, drag Sub-Category to the Rows shelf, to the right of the Region field.

Create a nested sort using the header

On the worksheet, hover over a viz axis.

Click the sort icon that appears at the top of the view.

One click sorts the data in ascending order. Two clicks sorts it in descending order. Three clicks clears the sort.

Now you have a nested sort where the subcategories are listed in descending order of sum of sales within each region. You can see that Chairs are the highest selling subcategory in the Central region, but in the East region, Phones are the best selling product; Chairs are the second-best selling product.

Create a Nested Sort using the Sort menu

Right click on the dimension you wish to sort and select Sort.

In the Sort dialog, select Nested under Sort By.

When using the Sort menu to create a nested sort, you can define the field and aggregation you wish to sort by. For example, you could sort the view by Profit even if Sales is the only measure in the view.

It is possible to create a nested sort on both the rows and columns shelves using this method.

Note: When creating a nested sort, the sort will propagate when you drill down through the dimensions. For example, a nested sort on Sub-Category will apply to Manufacturer and Item if you drill down to that level.

Sorting with one mark per pane

If your visualization is only one mark per pane, you can use the same processes as above to sort your data.

Create a Filtered Nested Sort

When you have dimensions on both the rows and columns shelf, a nested sort on both shelves might not produce clear results. The nested sort will apply on the columns shelf as if the data on the rows shelf was aggregated, and the nested sort on the rows shelf will apply as if the data on the columns shelf was aggregated.

Instead of sorting across all fields in a view, we can filter down to a single field and maintain the nested sort.

In the worksheet, hover over the lower viz axis of the dimension member you want to sort on. Click the Sort icon that appears next to the Dimension name.

The Nested sort will now apply only to that field.

To remove the Filtered Nested Sort, right click on the Dimension in the rows shelf and select Sort.

In the dialog that appears, click the X next to the filtered field. Then select Apply.