Add Total of Values in Tableau Stacked Bar Chart

While analyzing our company’s sales data, I wanted to compare sales by region to see the contribution of each product Category (Furniture, Office Supplies, Technology).

For this, I created a stacked bar chart where each bar represented the sales of a region and was divided into different categories.

Through this Stacked chart, the sales team found it difficult to understand the total sales per region since only the individual category contributions were visible in bars.

To make the visualization easy, I needed to add totals on top of each stacked bar, so that even though the bars are divided into categories, the overall regional sales total is clearly displayed.

In this Tableau tutorial, I will explain how to add the total of values in a Tableau Stacked Bar Chart.

Add Total of Values in Tableau Stacked Bar Chart

There are two methods through which we can add the total of all values in the Tableau stacked bar chart.

  • Add Total in Tableau Stacked bar chart using dual-axis
  • Add Total in Tableau Stacked Bar Chart using Reference Lines

Add Total in Tableau Stacked Bar Chart Using Dual-Axis

For this Tableau stacked bar chart, we will use the Tableau superstore data set to show the total of values at the top of stacked bars.

Now, connect the datasource with Tableau and follow the steps below to create a stacked bar in Tableau and show the total of values.

  1. To compare the Sales of product categories across regions, add the Sales to Rows and Region to Columns.
Show total in Tableau Stacked Bar Chart
  1. To distribute the sales of the region, we will stack the bar using the category. For this, add the Category to the Color card in the Marks section.
Stacked Bar chart in Tableau with Total values
  1. To add the values of stacked measures and the total at the top of bars, we will create a dual axis. For this duplicate, the Sales on the Rows and change the Marks type to Gantt bar.
Create a Tableau Stacked chart with total values
  1. Now, click on the second sales in the Rows and select Dual Axis.
Use dual axis to show total in tableau Stacked bar chart
  1. Now, remove the Category(Color) from the second Sales axis.
Add total of values in Tableau Stacked bar chart
  1. Now, we will add the labels for the values in both charts ( Gantt chart and Bar chart). The values in the Sales(1) chart will show the stacked values, and Sales(2) will show the values at the top of the stacked bar.
Show sales Total in Tableau Stacked bar chart
  1. If the values are not aligned at the top of the bars, then right-click on the Sales axis and select Synchronize Axis.
Add total in Tableau Stacked Bar Charts

With this, the total of the values will be stacked at the top of the bars as shown in the image below.

Create a Tableau Stacked chart with total on bars

This way, we can add the total at the top of bars in Tableau Stacked bar charts using the Dual-axis charts.

Add Total in Tableau Stacked Bar Chart Using Reference Lines

In this method, we will use the reference lines to show the total of stacked values at the top of the bars.

  1. Add the Region to Columns, Sales to Rows to show sales in various regions. Then, stack it by adding the Category in the Color card of the Marks section.
Add total in Tableau Stacked Bar Charts using reference lines
  1. To add the reference line, right-click on the Sales axis and select Add Reference Line.
Create a stacked Bar chart in Tableau with total
  1. Now, configure the reference line in the following way to show the total at the top of stacked bars.
    • In the dialog box, set Scope = Per Cell so that each Category gets its own total.
    • For Value, choose SUM(Sales).
    • Under Label, select Value to show the total number at the end of each stacked bar.
    • Format the line as None (remove the actual line) so only the total label appears at the top.
Add reference line to show total in Tableau Stacked bar chart
  1. Now the total of stacked values will appear at the top of the bars. If the total value is not aligned, then click on the value and select Format.
How to show total in tableau Stacked bar chart
  1. In the Reference Line Label, select Alignment as Middle. With this, values will be aligned at the top-center of the bars.
Align Total values in Tableau stacked bar chart
  1. We can also display the sales values for each category in the stacked bars. For this, select Marks -> Label -> Show mark labels.
Tableau stacked bar chart with total of values

Now, we can see the sales values for each category and also the total Sales for each region in the Tableau stacked bar chart.

Add total of Measure values in Tableau Stacked bar

This way, we can show the total values in Tableau stacked bar charts by using the reference lines.

Conclusion

In this Tableau tutorial, we have learned how to add the total of values on top of stacked bar charts. In the above examples, we used two methods to show the total values in stacked bars. One using a Dual-Axis and the other using Reference Lines.

By using either of these two methods, you can easily display the overall measure total in a stacked bar chart, while still keeping the distribution by categories visible.

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.