Sorting in Tableau

What is sorting in Tableau?

Sorting in Tableau refers to arranging the data in a particular order to help users with enhanced data visualization. Tableau supports built-in features that allow end users to sort the data with multiple touchpoints. By sorting the data, you can organize and apply customization to your dataset in a logical way to support your analysis and visualization. With the sorting option, you can control the order in which the data fields or dimensions in a table or visual are displayed, which will allow you to identify the relationships between these data fields.

A sample sorting in Tableau visualization looks like the one provided below.

Sorting in Tableau - Sample
Key Takeaways
  • Sorting in Tableau enables you to arrange the data in a certain order to help users with enhanced data visualization. 
  • By sorting the data, you can organize and apply customization to your dataset in a logical way to support your analysis and visualization. 
  • With the sorting option, you can control the order in which the data fields or dimensions in a table or visual are displayed and hence allow you to identify the relationships between these data fields.
  • You can sort the data either using manual sorting or through the computed sorting in Tableau
  • You can explore multiple options such as sort from the toolbar, sort from drag and drop, or sort specific fields in the viz while authoring in Tableau.
  • You can sort a hierarchical dimension, calculated fields, or even data when using filters in Tableau. 

How to Sort data in Tableau?

Tableau allows you various ways of sorting your dataset. These include:

#1 – Manual sorting

  • Manual or custom sorting in Tableau allows you to organize your data fields in a specific way by defining the conditions you want. 
  • You have greater flexibility and control over the arrangement of the fields as you can choose the sorting order
  • To perform manual sorting, you can follow the steps below
    • Step 1: Open a visualization using Tableau Desktop or Public version on your machine
    • Step 2: In the Tableau view, locate the Legend in the right-hand corner. Right-click anywhere in the white space in the Legend pane and choose the Sort option from the context menu.
Step 2
  • Step 3: In the Sort dialog box that opens, choose the Manual option from the drop-down menu under Sort By.
Sorting in Tableau - Step 3
  • Step 4: In the Sort dialog box, select a field you want to rearrange and choose the side buttons to move up or down in the list.
Step 4

#2 – Computed sorting

  • Computed sorting is a feature in Tableau that allows you to sort the fields in a table based on a measure used in Tableau view.
  • It allows you to arrange the dimensions based on measure values and helps you identify any relationships between the data fields.
  • To perform computed sorting, you can follow the steps below.
    • Step 1: Select the data field or fields you want to sort
    • Step 2: Hover your mouse over the field/s and then click on one of the Sort buttons, i.e., ascending or descending that is visible on the toolbar. 
Computed Sorting - Step 2
  • Step 3: In the Sort dialog box, choose the condition (Sort By field options) to sort the data and the sort order i.e. Ascending or Descending.
Sorting in Tableau - Computed Sorting - Step 3

You can specify other conditions as well to define the sorting logic for your visual.

Sorting in Tableau - Computed Sorting - Step 3 - logic

Examples

In this section, we will examine different examples of how to apply sorting to data visualization in Tableau.

Example #1 – Sort from an Axis, Header, and Field Label

In this example, we will create a data visualization in Tableau and then apply sorting to the visualization from the axis and field label. To apply sorting, we have used the Amazon Books dataset, which contains essential information about each book, including metadata such as the title, author, and price, as well as user-generated content like reviews and ratings.

To create a visual and then apply sorting in Tableau, follow the instructions below:

Step 1: Open your Tableau Desktop on your machine and import the Amazon Books dataset. The imported dataset can be accessed from the Data Source tab, as shown below. 

Example 1 - Step 1

Step 2: Navigate to a new worksheet. Drag the Price to the Columns shelf and Category and Language to the Rows shelf. Tableau will create a horizontal bar chart in the view as shown below.

Example 1 - Step 2

Step 3: Drag the Language to the Filters pane. In the Filter dialog box, uncheck the null and then click on OK.

Sorting in Tableau - Example 1 - Step 3

It will update the visual in the Tableau view.

Sorting in Tableau - Example 1 - Step 3 - Visual

Step 4: Hover your mouse over the horizontal axis, i.e., Price. You will notice a Sort icon visible next to Price. Click on the Sort icon.

Sorting in Tableau - Example 1 - Step 4

Step 5: As you can see, Tableau has applied sorting to the view based on the prices. Now, hover your mouse over a field label. Again, you will notice a sort icon next to the Language field label. Click on the icon.

Sorting in Tableau - Example 1 - Step 5

Tableau will further apply sorting to the view, as shown below.

Sorting in Tableau - Example 1 - Step 5 - sorting

Example #2 – Rank function

In this example, we will sort the dataset in Tableau using the Rank function. For this purpose, we have used the Dataset Salary 2024, which contains key variables such as salary, job title, experience level, employment type, employee residence, remote work ratio, company location, and company size. 

To apply sorting in Tableau using Rank function, follow the instructions below:

Step 1: Import the Dataset salary 2024 into Tableau either using the Tableau Desktop or Tableau Public interface.

Example 2 - Step 1

Step 2: In a worksheet, drag the Job Title to the Rows shelf and Salary in USD to the Columns shelf. Drag Salary in USD to the Label on the Marks card. Tableau will create a horizontal bar chart, as shown below.

Sorting in Tableau - Example 2 - Step 2

Step 3: Click on the text tables icon under the Show Me toolbar. It will display the data in a tabular format.

Example 2 - Step 3

Step 4: Right-click on the Data pane and choose Create Calculated Field option from the context menu.

Sorting in Tableau - Example 2 - Step 4

Step 5: In the calculation editor, specify the logic to use the Rank function and provide a meaningful name to the field. Here we have created a field called Salary Rank by Job Title which will assign ranks to the records in the table based on salary values. 

Sorting in Tableau - Example 2 - Step 5

Step 6: Drag the newly created calculated field to the Tableau view. Apply sorting in Tableau to the Salary in Usd measure. You will see the ranks for each of the values in the table.

Sorting in Tableau - Example 2 - Step 6

Example #3 – Nested Sort

In this example, we will apply nested sorting in Tableau using the Product Sales dataset. The dataset contains sales details such as Segment, Country, Product, Discount Band, Unit sold, and more for data analysis. To apply nested or sorting in Tableau with multiple dimensions, follow the instructions below:

Step 1: Import the Product Sales dataset using the File – Open navigator.

Example 3 - Step 1

Step 2: Drag the Segment and Product fields to the Rows shelf. Similarly, drag the Gross Sales and Profit to the Columns shelf. Drag the Product to the Colors on the Marks card.

Sorting in Tableau - Example 3 - Step 2

Step 3: In the Tableau toolbar, click on the sort descending icon. This will sort the view based on the Gross sales values.

Sorting in Tableau - Example 3 - Step 3

Step 4: Now select SUM(Profit) and click on the sort descending icon in the toolbar. 

Sorting in Tableau - Example 3 - Step 4

Tableau will update the visualization by applying sorting in Tableau based on Profits in descending order in the Tableau view, as shown below.

Sorting in Tableau - Example 3 - Step 4 - sorting

Sort Options While Authoring in Tableau

While authoring in Tableau, you can utilize additional sort options available in Tableau, which are outlined below:

  • Sort from the Toolbar

Tableau provides sorting options, such as Ascending or Descending, in the toolbar that you can use to apply data rearrangements.

Sorting in Tableau - Toolbar
  • To use these options, follow the steps below.
    • Choose a dimension you want to apply to sort. By default, Tableau applies sorting to the deepest or most indented dimension if you don’t choose any.
    • Click on either the Sort Dimension Ascending or Descending icon in the toolbar.
  • Sort by drag and drop
    • This option is for manual sorting of data fields and can be done via Legends in the Tableau view
    • To apply this sorting in Tableau option, choose a header in a viz or on a legend, as shown below. Drag the field to the appropriate position. You will notice a thick black line appears, which indicates that the field has been moved to that location.
Sorting in Tableau - thick black line
  • Sort specific fields in the viz
    • Tableau has functionality to allow you to sort specific fields in the visualization. To determine the sort order, Tableau uses the current ICU, i.e., the International Components for Unicode library.
    • To apply sorting in Tableau, you can follow the below steps.
      • Right-click on the field you want to sort and choose Sort
Sorting in Tableau - Sort Field
  • Choose an option from the drop-down menu under the Sort By header.
Sorting in Tableau - Sort by

The behavior for each of the above options is provided below

OptionDescription
Data Source OrderThis option allows you to sort the data in the data source. If you are using any relational data sources, this option sorts the data in a natural sort order. Natural sort order sorts the numeric data as per the numbers whereas, for alphabets, it is based on ASCII character. For multidimensional cube data sources, sorting is based on the hierarchical order of the members within a dimension
AlphabeticThis option alphabetically sorts your data, i.e., sort the [A-Z] before [a-z] and hence is case-sensitive. Similarly, for digits or numbers, they are sorted on a standalone basis. You can also create a non-sensitive sort by using functions such as UPPER or LOWER in Tableau
FieldUsing this option, you can use the field values, i.e., data aggregation, to identify the sort order
ManualUse the manual option to move the fields to a specific position either by dragging the fields or using the arrow keys
NestedYou can use the nested option to determine the sorting based on the aggregated field values.

Important Things to Note

  • You can apply sorting in Tableau from the tooltip for a header. This option is visible even when the Tableau view has a table calculation. For the Tableau view containing table calculations, this option creates a manual sort using the data available in the view.
  • When you apply sorting to a legend, the order of the marks changes. The bottom-most item available in the legend is downgraded to the bottom-most mark in the viz.
  • When you create a nested sort, the same is inherited when you apply drill down through the dimension fields.
  • When there are multiple panes, applying sorting can give you unsorted results in the Tableau view.

Frequently Asked Questions (FAQs)

1. What is the difference between sorting within a dimension and sorting within a measure in Tableau?

When you sort within a dimension, you can rearrange the fields at a specific dimension or levels within a dimension. Tableau doesn’t support sorting within a measure. However, you can apply sorting by creating calculated fields in Tableau.

2. Can I sort a hierarchical dimension in Tableau?

Yes, you can sort a hierarchical dimension in Tableau. Tableau supports sorting data fields at different levels of hierarchy.

3. How do I sort data in a calculated field in Tableau?

To sort data in a calculated field in Tableau, you may follow the below steps:

Create a calculated field in Tableau using the Created Calculated Field option
Use the field in Tableau visualization to apply the desired sorting

4. How can I sort data when using filters in Tableau?

To sort the data when using filters in Tableau, you can apply the data filter first followed by applying the data sorting to the filtered data. This will help you in sorting and filtering in Tableau.

Guide to What Is Sorting in Tableau. We learn how to sort data in different ways like manual sorting and computed sorting with examples. You can learn more from the following articles –

Auto Recover In Google Sheets

Timeline In Google Sheets

PI in Google Sheets

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *

CHATGPT & AI FOR MICROSOFT EXCEL COURSE - Today Only: 60% + 20% OFF! 🚀

X