KNOWLEDGE BASE

Displaying the label on top of the bar with the highest value


Published: 14 Jun 2023
Last Modified Date: 16 Jun 2023

Question

How to display a label on top of the bar with the highest value.

<IMAGE>
The example below shows a Bar in Bar chart of sales and targets, with the percentage of achievement label.
User-added image

Environment

  • Tableau Desktop

Answer

Please follow along with the attached sample workbook to the right of this text in the Attachments section.

<STEP 1>
Create Bar in Bar Chart
1. Connect to attached data source 'Test.xlsx' from Tableau Desktop.
2. Drag [Region] to Columns.
User-added image
3. With right clicking, drag [Target] to Rows -> Select AVG(Target).
User-added image
4. Drag [Sales] to Rows next to [AVG(Target)].
User-added image
5. Right click on [SUM(Sales)] placed in Rows -> Dual Axis
6. Right click on Sales Axis -> Synchronize Axis
User-added image
7. Open 'All' Marks -> Change the chart type to Bar.
User-added image
8. Open 'SUM(Sales)' Marks -> Click on Size -> Change the size of bar using slider.
User-added image

<STEP 2>
Create a Label
9. Create a new calculated field as following.
     Name : Percentage of Achievement
     Calculation : SUM([Sales])/AVG([Target])
10. Create a new calculated field as following.
     Name : Display Label Above Sales
     Calculation : IF SUM([Sales]) >= AVG([Target])
                          THEN [Percentage of Achievement]
                          END
11.  Create a new calculated field as following.
     Name : Display Label Above Target
     Calculation : IF AVG([Target])>=SUM([Sales])
                          THEN [Percentage of Achievement]
                          END
12. Open 'AVG(Target)' Marks -> Drag [Display Label Above Target] to Label.
User-added image
13. Open 'SUM(Sales)' Marks -> Drag [Display Label Above Sales] to Label.
User-added image
Did this article resolve the issue?