How to Sort Stacked Bar Chart in Tableau
A stacked bar chart is fantastic for comparing totals while also showing the composition of each total, but sorting them in Tableau can get surprisingly frustrating. The default alphabetical sort often hides the key insights you're trying to communicate. In this tutorial, we’ll walk through how to take control of your stacked bar charts and sort them in a way that tells a clear, compelling story with your data.
Why Sorting Your Stacked Bar Chart Matters
Sorting isn't just about making your chart look tidy, it's a fundamental part of data storytelling. An unsorted chart forces your audience to work hard, scanning back and forth to compare values and figure out what’s important. When sorted correctly, the same chart can reveal in a split second who your top performers are, which regions are lagging, or where the largest concentrations of a particular segment lie.
Imagine you're analyzing quarterly sales by marketing channel, with each bar broken down by product category. Simply sorting the bars from highest to lowest total sales immediately shows you which channel is driving the most revenue overall. It’s the difference between a confusing visual and a powerful, decision-driving insight.
Understanding Tableau's Default Sorting Behavior
By default, Tableau usually sorts the dimension you place on your axis alphabetically. So if you're plotting sales by country, your chart will show up as "Australia," "Canada," "Germany," "United States," etc., regardless of their sales figures. Similarly, the colored segments inside the bars are often sorted alphabetically by name.
This is rarely the most useful view for analysis. You almost always want to arrange your bars or sections based on a measure, like sorting countries by total sales or product categories by profitability. Let's look at how to override Tableau’s default and apply your own custom sorting logic.
Setting Up a Basic Stacked Bar Chart
Before diving into sorting, let’s quickly build a standard stacked bar chart to make sure we're starting from the same place. We’ll use a classic e-commerce example: analyzing total sales across different product categories within various regions.
Quick Step-by-Step Example
- Connect to a sample dataset like "Sample - Superstore" that comes with Tableau.
- Drag the Region dimension to the Columns shelf.
- Drag the Sales measure to the Rows shelf. This creates a basic bar chart.
- To turn it into a stacked bar chart, drag the Category dimension to the Color target on the Marks card.
You should now see four bars, one for each region, with each bar split into colored segments representing the "Furniture," "Office Supplies," and "Technology" categories. Notice the bars are probably sorted alphabetically by region - a "Central, East, South, West" problem that hides performance insights.
Method 1: Sorting The Bars by a Measure (The Easy Win)
The first and most common task is to sort the bars themselves. In our example, we want to see which region generated the most sales overall, from left to right. This requires sorting the Region dimension based on the SUM(Sales).
Step-by-Step Instructions
- Locate the Region pill on your Columns shelf.
- Right-click the Region pill and select Sort... from the dropdown menu.
- The Sort dialog box will open. In the "Sort By" section, select Field.
- For the "Sort Order," choose Descending. This will arrange your bars from largest to smallest. (Choose ascending if you want to see the smallest performers first).
- For the "Field Name," select the measure you want to base the sort on. In this case, choose Sales.
- The "Aggregation" will default to Sum, which is correct for this situation. Leave it as is.
- Click OK.
Instantly, your chart reorders itself. The region with the highest total sales now appears on the far left, and the region with the lowest appears on the far right (or vice-versa if you chose ascending). This is a simple but massive improvement in readability.
Method 2: Sorting the Segments Inside the Bars
Now for the trickier part: sorting the colored segments within each stacked bar. Notice how the categories "Furniture," "Office Supplies," and "Technology" - are probably still sorted alphabetically. This can create a jagged, confusing pattern inside your bars.
For better visual consistency, it’s often best to have the segments in each bar follow the same order. A common approach is to sort them by their total measure, with the largest segment at the bottom and the smallest at the top.
The Challenge and The Solution
You can't just drag the legend items into order easily and expect it to hold for dynamically changing data. The most reliable way to enforce a sort order on the color dimension is to set its default sort properties. We'll sort the Category dimension based on its total Sales.
Step-by-Step Instructions
- On the Marks card, find the Category pill that is determining the color.
- Right-click the Category pill and select Sort....
- This will open the same Sort dialog box as before, but this time it will apply the logic to the Category segments.
- Again, set "Sort By" to Field and "Sort Order" to Descending. For "Field Name", select Sales and leave the aggregation as Sum.
- Click OK.
Look closely at your chart now. All the colored segments should follow the same order in every bar (e.g., Technology on the bottom, then Furniture, then Office Supplies). This sorting is "global," meaning it ranks the categories based on their total sales across all regions, creating a stable, easy-to-read baseline for your comparisons. This makes it far easier to visually compare the contribution of a specific category across different regions.
Bonus: Let Users Decide How to Sort with a Parameter
To take your dashboard to the next level, you can give your audience control over the sorting. By using a parameter, you can let them choose whether to sort the chart by Sales, Profit, or Quantity with a single click.
Step 1: Create the Sort Parameter
- In the Data pane, right-click and select Create Parameter....
- Name it "Sort By".
- Set the "Data type" to String.
- Under "Allowable values," select List.
- In the list of values, add the names of the measures you want to allow sorting by. For example:
- Click OK. Right-click the parameter in the Data pane and select "Show Parameter" to display it in your view.
Step 2: Create a Calculated Field to Use the Parameter
The parameter itself doesn't do anything yet. We need a calculated field that tells Tableau which measure to use based on the parameter's selection.
- Right-click in the Data pane and select Create Calculated Field....
- Name it "Sort By Measure Selection".
- Enter the following CASE statement:
CASE [Sort By]
WHEN "Sales" THEN SUM([Sales])
WHEN "Profit" THEN SUM([Profit])
WHEN "Quantity" THEN SUM([Quantity])
END- Click OK.
Step 3: Apply the New Calculation to Your Sort
Finally, we'll swap out our original, hard-coded sort with this new dynamic field.
- Right-click your Region pill on the Columns shelf and select Sort....
- Under "Sort By," keep it set to Field.
- In the "Field Name" dropdown, select your new calculated field, Sort By Measure Selection.
- You might see a message about the field containing aggregate and non-aggregate arguments. If so, choose the option "Sort By... Field... Custom..." or just select the field. It usually self-corrects based on the context. Ensure the aggregation remains set to appropriate default like 'Sum' or 'Custom' as determined by Tableau.
- Click OK.
Now, when you use the "Sort By" parameter control in your view, selecting "Sales," "Profit," or "Quantity" will instantly rejigger the whole chart. It’s a powerful feature that makes your dashboards far more interactive and useful for exploratory analysis.
Final Thoughts
Mastering how to sort stacked bar charts is a core skill that separates good Tableau users from great ones. By moving beyond the alphabetical defaults and using field-based sorting, you can arrange your visuals to highlight your most important insights and guide your audience to the right conclusions.
Of course, for dashboards that you need ready in minutes, the manual clicks and setup in tools like Tableau can feel slow and repetitive. When we built Graphed , we designed it to skip these steps entirely by understanding plain English. You can simply ask, "Compare revenue and ad spend from Facebook Ads by campaign as a sorted stacked bar chart for the last 90 days," and instantly get a live dashboard that does just that, empowering your whole team to find answers without needing specialized technical skills.
Related Articles
How to Connect Facebook to Google Data Studio: The Complete Guide for 2026
Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.
Appsflyer vs Mixpanel: Complete 2026 Comparison Guide
The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.
DashThis vs AgencyAnalytics: The Ultimate Comparison Guide for Marketing Agencies
When it comes to choosing the right marketing reporting platform, agencies often find themselves torn between two industry leaders: DashThis and AgencyAnalytics. Both platforms promise to streamline reporting, save time, and impress clients with stunning visualizations. But which one truly delivers on these promises?