One of Tableau’s best features is its contextual awareness. It is a very smart program that generally knows what you are trying to do based on what you have done already. Unfortunately however, this feature can sometimes lead to automatic assumptions that may not align with your actual intentions. Additionally, these “smart” assumptions are usually rather inflexible. For this blog, I will be focusing on how this applies to stacked bar charts.
Let’s use an example for context. If you’d like to follow along, please open the superstore dataset from your Tableau repository. First things first, we need a stacked bar chart, so let’s take a look at sales by both category and sub-category.
- Begin by dragging the sum(sales) measure into rows, this will give us one bar with our total sales number across all categories.
- Next, drag the categories dimension into columns to split sales by category. You should now see 3 bars, one for furniture, one for office supplies, and one for technology.
- Let’s assume that the total sales numbers for each category are key to our analysis. Given this assumption, the next move will be to go to the labels marks card and check the box to “show mark labels.”
- And now, drag the sub-categories dimension into the color marks card to drill down even further. At this point, you should now have your 3 stacked bar charts.
- As you can see, when you bring sub-category into the view, Tableau automatically assumes that you want mark labels at the lowest level of aggregation. However, I previously mentioned that the total sales numbers for each CATEGORY (not sub-category) are key to our analysis. This is an example of Tableau’s contextual assumptions working against the user.
- Currently, we can only see labels at the sub-category level, but using this nifty little trick, I will show you how to de-aggregate your labels. The key here is some crafty manipulation using dual synchronized axes. To set this up, drag another sales pill into rows. You should now see two identical stacked bar chart panes.
- The next step is to right click the sales axis on the bottom pane and select dual axis. This will merge the two panes into one and put the 2nd sales axis to the right of your chart. This may also automatically change your chart types, but don’t worry about this just yet.
- To make sure both of our charts are working on the same scale, right click one of your sales axes and select synchronize axis. Now that we know that our two charts are using the same axis, you can go ahead and hide the extra sales axis on the right. Do that by right clicking the axis and deselecting “show header.”
- Next I’m going to go to my primary Sales marks card, and change the chart type back to bars. And then I’m going to go to my secondary sales marks card, and remove sub-category from color. I’m doing this because I’m going to use these marks to label sales at the CATEGORY level.
- Finally, change the 2nd chart type to gantt bars. As you can see, the sales labels should now be available at the category level.
- The only thing left to do now is to go to the color card and turn the opacity all the way down to 0% to make the gantt bars disappear. Additionally, go back to the primary sales marks card and deselect “show mark labels,” so that the category level sales at the top are the only labels showing.
And that’s it! A quick nifty workaround for a common, annoying situation that most Tableau users will experience at least once.