8 Replies Latest reply on Sep 21, 2016 6:12 AM by Marc Maleika

# Stacked Bar Chart

Hello,

Have been trying to figure out this bar chart for few hours now but no success:

I would like to create a stack bar chart from the following two bar charts in attached tableau file.

In a second graph I would also like the daily stacked bar charts to be 100%.

Many thanks

• ###### 1. Re: Stacked Bar Chart

hi Marc,

Yes we should be able to do this...just one quick question!

Are the New Visitors included in the Vistors number? So if we had 100 New Visitors and 200 Visitors...would that be 50%/50% or 33%/66%?

• ###### 2. Re: Stacked Bar Chart

Amazing thanks a lot!

And good question: "new Visitors" are included in "visitors", so out of 200 visitors you would have 100 new visitors, so 50%, 50%.

m,

• ###### 3. Re: Stacked Bar Chart

hi Marc,

Thanks for the info!

So hopefully this does the trick...

first thing...if we want to stack different measures onto a chart, we need to use the (Tableau generated) measure names/values, which act like pseudo-dimensions and measures for measures.

So in order to make these %ages...I first created the %age of new visitors

[%age New Vistors]

SUM([Visitors New])/SUM([Visitors])

and the to get the remainder (non-new)

[%age Non-New Vistors]

SUM(zn([Visitors])-zn([Visitors New]))/SUM([Visitors])

As aggregate calculations, they are calculated at the level in the Viz...in this case Day, but if you looked by week, month...etc. it would remain correct.

Hope that helps, and makes sense.

• ###### 4. Re: Stacked Bar Chart

Thanks Simon,

I am still having problems doing the bar chart. see attached.

• ###### 5. Re: Stacked Bar Chart

OK...So you just need to replace the colour, currently on SUM([Visitor Numbers]), with the measure names. This will add measure names (the 2 you have selected) to the VizLoD and so stack the bars. You can actually just add it to the detail pane, but both bars would get the same colour (although you can, if you turn on bar borders, just about see them).

• ###### 6. Re: Stacked Bar Chart

Great - this worked. Thanks! Now I am only wondering how to make Tableau “new visitors” part of “visitors” and not individual bars that are staked on top of each other.

• ###### 7. Re: Stacked Bar Chart

I thought the stacking and 100% was what we were trying to do here!!?

Anyway both the calculated fields I provided are divided by Visitors so we get %ages, and then stacked to makeup 100%.

So we can just use the first part to get this...

[Visitors - Existing]

SUM(zn([Visitors])-zn([Visitors New]))

and then [Vistors New] you already have (using SUM)...and so stacking these 2 measures will give the total height of the stacked bar being that of total visitors...where the new will be a different colour.

Hope that makes sense?

• ###### 8. Re: Stacked Bar Chart

Worked, thanks!