How to Sort in Tableau

Cody Schneider

Arranging your data in the right order is one of the quickest ways to bring clarity to a visualization. Tableau offers several ways to sort your data, from simple one-click operations to more advanced custom arrangements. This tutorial will walk you through the different sorting methods available in Tableau so you can organize your views and make your dashboards more insightful.

The Easiest Method: One-Click Sorting

The fastest way to sort your data in Tableau is by using the single-click sort icons that appear when you hover over axes or headers. This is perfect for quick, on-the-fly analysis directly within your visualization.

Sorting on an Axis

When you have a chart with a quantitative axis (like a bar chart showing sales), hovering over that axis reveals a small sorting icon. Clicking this icon instantly reorders the corresponding dimension bars.

  • For a horizontal bar chart: Hover over the Y-axis label (the names of your categories). A sort icon will appear. Clicking it will sort the bars and labels in ascending or descending order based on the measure value.

  • For a vertical bar chart: Hover over the X-axis header (the dimension members along the bottom). A sort icon will appear next to the header name. Clicking will reorder the bars.

For example, if you have a bar chart showing Sales by Sub-Category, clicking the sort icon on the Sales axis will instantly arrange your sub-categories from highest-selling to lowest-selling, or vice versa with another click.

Sorting on a Header in a Table

If you're working with a text table or a datasheet, you can use a similar method. Hover over a field's header, and a sort icon will appear. Clicking it sorts the entire table based on the values in that column. This is incredibly useful for instantly ranking items in a large list.

Sorting from the Toolbar

Another simple way to apply a basic sort is by using the sort buttons in the Tableau toolbar at the top of the window. You'll see two buttons with bars of increasing and decreasing size, representing ascending and descending sorts.

To use this method:

  1. Click on the specific measure or header you want to sort by in your view. This makes it the "active" field. For instance, in a view with Sales and Profit, click the Sales header to focus on it.

  2. Click the ascending or descending sort button in the toolbar.

This method sorts all dimensions in the view based on the selected measure. For example, if you have Region and State in your rows, sorting by SUM(Sales) will order the regions, and within each region, the states, by their sales performance.

For Full Control: The Sort Dialog Box

For more detailed control over your sorting logic, you need to use the Sort dialog box. This is where you can define specific rules that aren't available through a single click. To access it, right-click (or control-click on Mac) the dimension pill in the view that you want to sort and select "Sort..."

This opens a window with several advanced options.

Sort By Data Source Order

This is the default sort order. It sorts your dimension based on how the data is stored in the original data source. For most text-based fields, this ends up being an alphabetical sort, but for numerical or specific data types, the order might differ.

Sort By Alphabetical Order

As the name suggests, this option sorts the members of your dimension alphabetically. You can choose A-Z (Ascending) or Z-A (Descending). This is useful when you want to organize item names, customer names, or geographical locations in a universally understood order.

Sort By Field

This is one of the most powerful and common sorting methods. It allows you to sort a dimension based on the value of another field, typically a measure.

For example, you could sort the Customer Name dimension based on the SUM(Sales). This shows you which customers are most valuable.

When you choose "Field," you'll get two more options:

  • Sort Order: Choose Ascending or Descending.

  • Field Name: A dropdown list of all available fields in your data source. You select the measure you want to use for the sort.

  • Aggregation: Select how the measure should be aggregated (Sum, Average, Count, etc.). By default, it uses the aggregation that's already in the view, but you can change it here.

Sort By Manual Order

Sometimes, your data needs to be sorted in a way that has no relation to its name or value. For instance, you might want to order survey responses from "Very Dissatisfied" to "Very Satisfied" or arrange sales regions in a specific non-alphabetical sequence (East, West, North, South).

The manual sort option lets you drag and drop the dimension members into whatever order you need. Simply click on a member and move it up or down the list until it's in the correct position.

Sort by Nested

Nested sorting is used when you have multiple dimensions in the rows or columns. It sorts the "inner" dimension independently within each pane of the "outer" dimension.

Imagine a view showing Sales by Category and Sub-Category. A non-nested sort would try to order all sub-categories globally by Sales, which can jumble the visualization. A nested sort, however, ranks the sub-categories within each category. So, the highest-selling sub-category in "Technology" appears first under Technology, and the highest-selling sub-category in "Office Supplies" appears first under Office Supplies.

You access this by selecting "Nested" from the "Sort by" dropdown in the Sort dialog box.

Advanced Sorting with Calculated Fields

What if you want to sort by a logic that doesn't exist in your data? This is where calculated fields come in. By creating a new field, you can define a custom sort order and apply it to your dimensions. This technique is especially useful for handling things like custom time periods or specific categorical rankings.

Let's say you want to sort the months of the year in chronological order (January, February, March...) instead of alphabetical order (April, August, December...).

Step 1: Create the Calculated Field

Create a calculated field called Month Sort with a formula like this:

`` CASE [Month Name] WHEN "January" THEN 1 WHEN "February" THEN 2 WHEN "March" THEN 3 WHEN "April" THEN 4 WHEN "May" THEN 5 WHEN "June" THEN 6 WHEN "July" THEN 7 WHEN "August" THEN 8 WHEN "September" THEN 9 WHEN "October" THEN 10 WHEN "November" THEN 11 WHEN "December" THEN 12 END