12 Replies Latest reply on May 9, 2016 2:45 AM by Sabine Honer

# How to display the percent of total on top of bars?

Hi All,

again I am struggling displaying labels at the top of bars.

We have created a calculated field to flag data records, if they fall in category "Bottom half" or "Top half".

Now we would like to display at the top of the two bars ("Bottom half" and "Top half") the percent of total.

We tried reference line, but couldn't get percentages.

We tried it by using calculation (using LOD), but can't use our first calculated field within LOD calculation.

We are really thankful for any kind of hints.

Best regards

Sabine

• ###### 1. Re: How to display the percent of total on top of bars?

Hello Sabine,

We can do this, but first I want to double check what your trying to do exactly with this calc...

if [Profit]/[Sales]<{EXCLUDE [Order ID]:MEDIAN([Profit]/[Sales])} then

"Bottom half"

ELSE

"Top half"

END

This may not be the correct calculation you are after, but it depends on what you are after.

Can you elaborate?

Regards,

Rody

3 of 3 people found this helpful
• ###### 2. Re: How to display the percent of total on top of bars?

Hi Sabine,

I would like to echo Rody's comment above. To bring the labels above the top of bars, you could do a Dual Axis chart, where the second measure is the Percentage value. On the Marks card for the second measure, change the Mark type to 'Text' and drag the Percentage field on the Label card. Format the Label to put empty lines after the text so that there is space between the top of bar and the actual % value.

Hope this helps! Good Luck,

Regards,

Namrata

3 of 3 people found this helpful
• ###### 3. Re: How to display the percent of total on top of bars?

Hi Rody,

thank you very much for your question.

I got workbook from a colleague and as far as I understood is, that the calculation should calculate the median on the data set (either on whole data set or for filtered data set) and see, if quotient is either above or below it.

Then number of unique order ID, that fall either above or below median should be counted and percentage should be displayed.

Best regards

<Sabine

1 of 1 people found this helpful
• ###### 4. Re: How to display the percent of total on top of bars?

Hi Namrate

I will try it.

Best regards

Sabine

2 of 2 people found this helpful
• ###### 5. Re: How to display the percent of total on top of bars?

Ok I understand.

So there are a couple things to keep in mind, the most important of which is the Level of Detail of your viz.

With Superstore, you can have multiple records per Order ID, so you would need to decide whether or not you want to Find the Median of all individual records, OR the Median of all Order IDs. These numbers are different.

How we write the calc, and how we construct the viz depends on this, as aggregations will happen based on the Level of Detail of your visualization + any LoD calcs you may be using.

Theoretically, your "Below Median" and your "Above Median" counts should always be roughly 50%, as that is the definition of Median. But this again depends on whether or not you are looking to compare the Median of Order IDs, or the Median of Records.

I can help you with either/or, but want to make sure I'm not giving an incorrect answer.

Regards,

Rody

1 of 1 people found this helpful
• ###### 6. Re: How to display the percent of total on top of bars?

Hi Rody,

As I am still learning Tableau I would love to see the result or both options, but I don't know, how complicated and how long it will take to create approaches.

But here Median should be calculated based on all individual records.

Best regards

Sabine

1 of 1 people found this helpful
• ###### 7. Re: How to display the percent of total on top of bars?

I think this is what you are looking for

Please have a look at the attached workbook

If you have any questions please reach out and I can explain

4 of 4 people found this helpful
• ###### 8. Re: How to display the percent of total on top of bars?

Although this will show you how to create the visualisation. It does not answer Rody's Point of what calculation you actually require for your Median.

Hope it helps you in some way

1 of 1 people found this helpful
• ###### 9. Re: How to display the percent of total on top of bars?

Hello Khalid,

It is working

I have one last question of you don't mind. And I am sorry, if it might be a stupid question.

Why exactly is the field "All" needed?

Best regards

Sabine

• ###### 10. Re: How to display the percent of total on top of bars?

Hi Sabine,

It has no significance in the view you can remove 'All' field, it will not effect your visualization.

Regards,

Swarup.

• ###### 11. Re: How to display the percent of total on top of bars?

Hi Sabine,

I am using a level of detail calculation.
To do the calculation on all data, to avoid confusion on what level I am calculating I create an all field and use this for the level of detail.

There may be other ways of achieving this but this seems the simplest for me.

Regards,

Khalid

• ###### 12. Re: How to display the percent of total on top of bars?

Hi All,

thank you very much for answering all my questions :-).

It is awesome

Have a great day,

Sabine