Sort Values in Tableau Stacked Bar Chart

Recently, I created a stacked bar chart to compare the product sales across the regions. In that chart, I faced an issue where the segments within each bar followed the same global order. That meant every bar was sorted in descending order by its overall value, rather than by the values from each bar.

For example, in the East region, Furniture was the top seller, while in the West, Technology was leading. But Tableau wasn’t showing that difference because it was showing the same order across all bars.

As a solution, I combined the values and sorted the segments within the stacked bars by value. With this method, each bar’s segments were sorted separately to see which category is contributing the most within each group.

In this Tableau tutorial, I will explain how to sort values in a Tableau Stacked bar chart with global sorting and sorting in each bar.

Sort Stacked Bar Chart in Tableau by Values

To sort the stacked bar chart in Tableau by values, there are two approaches: basic and advanced sorting.

  • Sort values in a Tableau stacked bar chart with global sorting
  • Sort values in a Tableau stacked bar chart in each bar by segments

Sort Values in Tableau Stacked Bar Chart With Global Sorting

In this method, we will sort the bars by total, and the segments within the bars follow a single global order.

Connect the Tableau with the Superstore dataset and follow the steps below to create a stacked bar chart with global sorting.

  1. Drag the Category to the Columns and Sales to Rows. With this, we will get the bar chart showing sales for each category.
Sort Values in Tableau Stacked Bar Chart
  1. To stack the bars, add the region to the Color card in the Tableau.
Tableau stacked bar chart sort values
  1. To display the sales values for each region in the category bars, add ‘Sales’ to the Label card in the Marks section.
Tableau stacked bar chart sorting
  1. To add sorting, click on the Category in the Columns and select Sort. In the next window, select “Sort by” as “Field“. After this, select the Sort Order and then choose the measure of sorting (Sales).
Sort Values in Descending in Tableau Bar chart

With this, bars are ordered by total Sales, and all segments follow the same global order.

Global sorting for values in Tableau

This way, we can sort the values globally in the Tableau stacked bar charts by following the above steps.

Sort Values in Tableau Stacked Bar Chart in Each Bar by Segments

In this method, we will apply advanced sorting, where the values will be sorted in increasing or decreasing order individually in each bar.

Connect the Tableau with Superstore data and follow the steps below.

  1. To create the stacked bar view, drag Category to Column, Sales to Rows,  Region to Color, and Sales to Label.
Tableau stacked bar chart with sort values
  1. For sorting, go to the Color card, right-click Region, and then select Attribute.
Sort Values by segment in Tableau
  1. In the Dimensions pane, hold the CTRL key, click Category, and then click Region. Now, right-click Region, and then select Create > Combined Field.
Value sorting in Tableau Stacked bar chart
  1. Click on the Category & Region detail card and select Sort.
Tableau value sorting in Stacked bar chart
  1. In the Sort dialog box, do the following, and then click OK.
    • In the Sort By, select Field.
    • For Sort Order, select Descending.
    • For Field, select Sales.
    • For Aggregation, select Sum.
Sorting Segments Within Stacked Bars by Value

With this, we can see that each bar now sorts its own segments based on the segment’s contribution within that bar.

Tableau stacked bar chart by sorting segments

This way, we can sort values in a Tableau stacked bar chart in each bar by segments.

Conclusion

In this Tableau tutorial, we have learned how to sort values in a Tableau stacked bar chart in two ways. In the above examples, by using global sorting, all bars are displayed in the same order. In another method, by sorting within each bar, where segments are arranged based on their contribution in that specific bar.

You may also like to read:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.