This blog is actually more of a self reference on how to make a stacked bar chart in Tableau. For some reason, despite how simple they look, stacked bar charts have always given me strife. Whenever I need to make one, for the life of me I can never remember how. That changes today!
A stacked bar chart is basically a bar chart split into sections. If you want to split one bar into many, you first have to ask? Does my data support that?
Lets try and make some stacked bar charts with everyones favourite dataset… Superstore!
TYPE 1: Simple Stacked Bar Chart
Is the measure aggregated (a combination of different categories/segments/dimensions)? If so, then your aggregate can be split into whatever dimensions are aggregated in the data.
This is more a question of the granularity of your data, since aggregate measures change the level of granularity.
- Drag Sales to a Colum or Row to get an aggregation of Sales (SUM, AVG, COUNT, etc.). The aggregation means that you’re actually getting result of a bunch of rows which may or may not be part of a specific dimension.
- Identify at what level you want your bar to be split into (the dimension).
- Drag that relevant dimension to DETAILS on the Marks card. This changes the level of detail of your measure to the level of that dimension. If instead you dragged it to rows/columns, each row/column would be a different segment of that dimension.
- Pro tip: Distinguish the different stacked bars by dragging that Dimension to COLOUR.
TYPE 2: 100% Stacked Bar Chart
To make a 100% stacked bar chart, we need the each aggregation to be relative to the overall total. We could make a Calculated Field containing:
SUM([Measure]) / TOTAL(SUM([Measure]))
This calculation, if a dimension is in the DETAILS pill, will calculate the sum of sales for each dimension divided by the sum of sales across all dimensions (changing the units to a percentage of the total).
OR we could just do a quick table calc…
Right Click > Quick Table Calculation > Percent of Total
TYPE 3: Set Stacked Bar Chart
You can also create stacked bar charts with Sets.
If you add a Dimension to a set, and select the relevant members of the set, you can segment whatever aggregated measure you want by the Set (if they’re somehow related). You have two options:
- In/Out of Set – separates the bars as either being in or out of the set that you created
- Members of Set – only shows you the members of the set
Similarly to the other bar charts, if you add the Set to a detail or colour pill, then it will segment your data appropriately.
TYPE 4: The Cheat Method
Just highlight both a Measure and a Dimension, click on ‘Show Me’ on the right side of the window, and select Stacked bar chart.
Well there you go, you’ve done it. You made a stacked bar chart!
Use your skills wisely.