KNOWLEDGE BASE

Add a Label to the Top of a Stacked Bar Chart


Published: 29 Sep 2016
Last modified date: 20 Jul 2023

Question

How to add a label to the top of a stacked bar chart.

For example, adding the total sales to the top of a stacked bar chart where every segment is a region's sales (option 1). Or, adding a label for the percent of total central region sales to the top of the stacked bar chart (option 2).

Environment

Tableau Desktop

Answer

Option 1: Add a total reference line

These directions begin with the stacked bar already created. For full directions, see the "Option 1" worksheet in the workbook downloadable from the right-hand pane of this article
  1. Right-click the Sales axis in the view and select Add Reference Line
  2. In the Add Reference Line, Band or Box dialog, do the following and click OK:
    1. For Scope, select Per Cell
    2. For Value, select SUM(Sales) and Total
    3. For Label, select Value
    4. For Line, select None
  3. Right-click one of the reference values in the view and select Format...
  4. In the left-hand Format Reference Line pane, under Alignment, select Centre for Horizontal


Option 2: Create a dual axis graph with the stacked bar on one axis and the total/label on the other axis.

Use this option when the value to add at the top of the stacked bar chart is not the total. These directions begin with the stacked bar already created. For full directions, see the "Option 2" worksheet in the workbook downloadable from the right-hand pane of this article
  1. Create a new calculated field called "Total Sales per Category" and use the following formula:
    1. IF FIRST() = 0
      THEN SUM({FIXED [Category]: SUM([Sales])})
      END
  2. Drag [Total Sales per Category] to the Columns shelf next to SUM(Sales)
  3. Right-click on [Total Sales per Category] on the Columns shelf, and select Compute Using > Region
  4. Open the [Total Sales per Category] the Marks Card and move Region from Colour to Detail
  5. On the same Marks Card tab, change the chart type from Automatic to Gantt Bar
  6. Right-click the NULL indicator in the view and select Hide
  7. Create a new calculated field called "Percent of Total Label - Central" and use the following formula:
    1. SUM(
      IF [Region] = "Central"
      THEN [Sales]
      END)
       /
       SUM({FIXED [Category]: SUM([Sales])})
  8. Drag [Percent of Total Label - Central] to Label on the [Total Sales per Category] Marks Card tab
  9. Right-click on [Percent of Total Label - Central] on the Marks card and select Format...
  10. Change the number format to Percentage.
  11. Right-click on [Total Sales per Category] on the Columns shelf, and select Dual Axis
  12. Synchronise the axis
Did this article resolve the issue?