KNOWLEDGE BASE

Add Percent of Total Label at Top of Stacked Bar Chart


Published: 29 Sep 2016
Last Modified Date: 25 Aug 2017

Question

How to add a label for Percent of Total (of one mark) so that the percentage is displayed on the end or top of the stacked bar chart.
 

Environment

Tableau Desktop

Answer

Create a dual axis graph with the stacked bar on one axis and the total/label on the other axis.
The following instructions are based on Superstore sample data.

Prepare the view:
  1. Drag Category to Rows
  2. Drag Sales to Columns
  3. Drag Region to Color

Find percent of total for the Central region and display the percentage at the end of the stacked bars.
  1. Create a new calculated field called "Total Sales per Category" and use the following formula:

    IF FIRST() = 0
    THEN SUM({FIXED [Category]: SUM([Sales])})
    END

  2. Drag "Total Sales per Category" to Columns next to Sales
  3. Right-click on "Total Sales per Category" on Columns and select Compute Using > Region.
  4. Go to the "Total Sales per Category" tab on the Marks Card and move Region from Color to Detail.
  5. On the same Marks Card tab, change the chart type from Automatic to Gantt Bar.
  6. Hide NULL indicator in the view.
  7. Create a new calculated field called "Percent of Total Label - Central" and use the following formula:

    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" tab on the Marks Card
  9. Right-click on "Percent of Total Label - Central" on the Marks card and select Format. Change the number format to Percentage.
  10. Right-click on "Total Sales per Category" on Columns and select Dual Axis.
  11. Synchronize the axis and convert the first axis to Bar chart and the second axis to Gantt chart if the chart types change.
Did this article resolve the issue?