12 Replies Latest reply on Jan 19, 2013 9:04 AM by Kevin Sullivan

# Bar in Bar Labels

I have a bar in bar chart with 3 bars based on counts and now want to add the labels for each bar to be the percent.

• ###### 1. Re: Bar in Bar Labels

Kevin,

If you put a copy of the measure field you are using for the bar on the label shelf and then right click the field, you can select "Quick Table Calculation" --> "Percent of Total".  If you are not familiar with table calculations, you might want to take a look here: http://www.tableausoftware.com/learn/tutorials/on-demand/advanced-training-table-calculations or do a search.

If you are still stuck, reply and attach a copy of your workbook (save it as a packaged workbook with the data extracted -- .twbx) and I'd be happy to take a look.

Joshua

• ###### 2. Re: Bar in Bar Labels

Here is my example....  you will see the fields marked as percents that i want to label the bars with.

• ###### 3. Re: Bar in Bar Labels

Kevin,

Woah!  Wasn't expecting that level of complexity.  Now I see the difficulty.

Catherine Rivier has a solution here for two measures as a stacked bar: http://community.tableau.com/message/197547

But you have three measures which makes the dual axis solution not work as well.

The best I came up with on short notice  was a single label that contained all three fields.  Not the prettiest, I'll admit (and I didn't take the time to clean up the string formatting for the percents).  Maybe some other contributors will have some better ideas.

Here's the calc:

"Into:  " + LEFT(STR([Vert Division Into Org %] * 100), 4) + "%

Out:    " + LEFT(STR([Vert Division Out Org %] * 100), 4) + "%

Within: " + LEFT(STR([Vert Division Within Org %] * 100), 4) + "%"

• ###### 4. Re: Bar in Bar Labels

can you send me back the twbx with that label working?  I copied your formula into a new calculated field and dragged it to the Label pill and it doesnt appear.  Thanks for all your help!

• ###### 5. Re: Bar in Bar Labels

Sure!  Here it is.  I made an arbitrary change to the calculated field Headcount (setting it to be 1) as I noticed that it was used in the % calcs, but was always null.  I wasn't entirely certain what the data represented.

Joshua

• ###### 6. Re: Bar in Bar Labels

thank you so much!  I do need that Headcount field though to be based off the If statement of if type equals Headcount then 1 else 0.  when i have it like that the labels dont appear but when i have it like you did headcount it works....  any work around for this?

• ###### 7. Re: Bar in Bar Labels

Kevin,

I think it would be fine to put it back to the way you had it.  Is this sample data?  I just didn't see any records where the type was "Headcount".

Joshua

• ###### 8. Re: Bar in Bar Labels

Yes it was sample data.  The Headcount field is a calcultation off of the field Type with this formula:  If [Type]="Headcount" then 1 else 0 end

When I have it like that the labels dont show but but they do when I change it to how you had it which unfortunately counts too many records.

• ###### 9. Re: Bar in Bar Labels

Kevin,

I'm sure the Headcount calculation is correct the way you had it.  The only issue is with the sample data.  In that data set, the only time the type is headcount is when the Type and Division Movement is null.  That means that all the % calculations will always be NULL and my label calculation that used those % calculations will be null.

So, if you try it with a full/production data set, does it work?

• ###### 10. Re: Bar in Bar Labels

Also, the label calculation could be updated to:

"Into:  " + LEFT(STR(ZN([Vert Division Into Org %]) * 100), 4) + "%

Out:    " + LEFT(STR(ZN([Vert Division Out Org %]) * 100), 4) + "%

Within: " + LEFT(STR(ZN([Vert Division Within Org %]) * 100), 4) + "%"

so it will show 0 instead of evaluating to NULL.

1 of 1 people found this helpful
• ###### 11. Re: Bar in Bar Labels

labels showed with that formula but as all zero percent so it must be something else wrong?

• ###### 12. Re: Bar in Bar Labels

when i drop the label into a text table on a new worksheet it does show that label as I want.....  It just isnt working on my bar in bar sheet