Note: The following is a guest post by Tableau enthusiast Matt Chambers.

For Makeover Monday, I wanted to tell the story of how Facebook is making an effort to make clean and renewable power its primary source of energy. I wanted to be able to sort the stacked bars by energy usage percentage by year. Here's how it's done:

1. Build your stacked bar chart in Tableau.

2. Create a combined field using the dimensions you want to sort by. In this case, I want to sort by energy source by year.

3. Drag the combined field to the detail and sort by the measure. Here, I am sorting by Amount.

4. Finally, drag the dimension that you are sorting by to the detail. I am using Energy Source in this example.

5. Now you have a stacked bar that is sorted by two dimensions. In my example, it is sorted by energy source and date. This allows for some nice interactivity that allows you to show trends and magnitude simultaneously. In my example, I am using it to show the rank of the energy sources while also showing the magnitude against other energy sources.

Please comment below with any questions or download the workbook to see how it's done.

For more tips, tricks, and vizzes by Matt, check out his Tableau Public profile page and his blog. You can also connect with him on Twitter @sirvizalot.


Looking forward to using this tip! Thank you

Wow. It is really amazing. Can you please explain me the technical stuff behind it. How creating a combined field and placing the energy source in detail worked out ?. Thanks for sharing it.

It might help to think of the combined field as a way of identifying each individual piece of each bar chart. Without the combined field, you can move ALL the green segments of each bar to the top, or ALL the pink segments to the bottom. If we want to be able to move the green segment from 2011 to the top but the green segment of 2012 to be one down from the top, we need to be able to refer to each segment individually. That's what the combined field does--it gives a unique identifier to each segment, essentially breaking out coal 2012 from coal 2013.

This is great! Like Elavar, I am struggling to understand why the sequence of steps that you mentioned had to happen for this to work. Would you be able to elaborate please?


Does this technique require Tableau 10?

Nope, earlier versions also have create >> combined field menu

Brilliant, thanks for your tip. I will definitely use this.

On Step 4, for this example why does the Energy dimension need to be put on the detail shelf? It is already on the color shelf, so it already defines the level of detail. Perhaps it is a best coding practice in case color is used for something else?

It's because I didn't have Energy Source as an attribute on the color shelf. If you change it to an attribute, you can take Energy Source off of the level of detail.

Great tip/blog! I would go further with bringing in the AVG(Amount) to Size so the end result would be similar to a funnel chart.