Creating Tableau Stacked Bar Chart with Percent of Total and Totals on Top
A Stacked bar chart is easy to create in Tableau but displaying totals at the top of the bars can be tricky. One way to achieve this is by using a reference line. However, it becomes challenging if you need to display different measures in the stacked bars and totals. For instance, displaying the percent of total sales in the stacked bar while showing total sales at the top. In this blog, titled “Creating Tableau Stacked Bar Chart with Percent of Total and Totals on top”, we will explore how to accomplish this effectively.
Our objective is to create a stacked bar chart similar to the one shown below. It displays the percent of total sales for different segments within a category, with total sales shown at the top of the bar.
Steps to Create a Stacked Bar Chart to Display Percent of Total Sales
We will first create a stacked bar chart to display percent of total sales.
- Launch Tableau desktop and connect to Sample – Superstore.XLS and use the Orders table.
- On a new sheet, from the data pane, place Category on Columns and Sales on Rows. Sales will be displayed as Sum(Sales).
- Place Segment on Color (under Marks) this will create a Stacked bar chart.
- Creating Percent of total sales. To display percent of sales, we need to use the Table calculation. Click on Sum(Sales) on Rows and select Percent of Total from the Quick Table Calculation as shown in the figure below:
5. Hold the CTRL key on your keyboard and drag/place Sum(Sales) table calculation (from Rows) on the label (under Marks). The final Stacked bar will be displayed as shown in the figure below. For each category, it displays percent of sales for different segments. It also displays the color legend for Segment.
Notice the above chart does not display total sales for each bar. In the below steps we will work on it.
Steps to display Total Sales at the top of the stacked bar chart:
- From the data pane, place Sales on Rows (on the right of Sum(Sales) table calculation. This will display two charts on two axis.
- Select the second Sum(Sales) on Rows and remove Segment from the color and Sum(Sales) table calculation from the Label.
- Select the second Sum(Sales) again and from the data pane place Sales on Text (under Marks) and from the Marks change the chart type to Line as shown in the figure below:
4. Now, select the second measure Sum(Sales) on Rows and from the drop-down select Dual-axis. This will display both the charts on the same axis. If chart type of the first measure Sum(Sales) changes to circle or something else. Select the first Sum(Sales) and from the Marks, change the chart type to Bar.
As shown in the chart below, you will notice that total Sales is getting displayed inside the bars and shows a trend line. We will fix this soon.
Our objective is the remove the display the totals outside the bar and hide the line.
5. One-by-one click on the Sum(Sales) data points/marks on the individual bars and reposition/drag them outside the bars as shown in the figure below:
6. To hide the line, select the second Sum(Sales) on the Rows. Reduce the size of the line from the Marks. Also, click on Color and change the opacity of the line to 0%.
7. We can hide the left and right axis as they are not required. Right-click on the right and left axis and uncheck Show Header.
This will produce the required chart with Percent of Total Sales displayed in the bars and Total Sales displayed at the Top of each bar.
Stacked bar chart can also be used to display two different measures, such as Profit and Quantity. Learn how to create a Stacked bar chart with two measures and totals of the stack at the end.
About the Author
Chandraish Sinha is the founder and President of Ohio Computer Academy, a company dedicated to providing IT education. An enthusiastic IT trainer, Chandraish embodies his company’s motto: Inspire, Educate & Evolve.
He has 20+ years of experience in Information Technology. He is an accomplished author and has published 11 books covering Business Intelligence related topics such as, Tableau, Power BI and Qlik. Checkout his Amazon Author profile.
His latest book Excel Basics to Advanced covers all the aspects of MS Excel and provides exercises for self-learning.
Similarly, his recent book, Dashboarding with Tableau, covers all the features in Tableau and includes exercises for self-learning.
He has implemented IT solutions in various domains viz. Pharmaceutical, Healthcare, Telecom, Financial and Retail.
He blogs regularly on various IT topics. Check them out in the links given below: