Each bar is a stack of small blocks of various sizes. Usually the blocks are all sorted by the same category, uniformly across all the bars. How to sort each bar individually according to the sizes?
I wondered about the same question before, but never actually solved it. So this is the time to give it a shot. It worked out pretty well. Based on the superstore data set, I created stacked bar chart showing Sales per Year and per Sub-category.
The solution is fairly simple: create a LOD expression of Sales by Year and Sub-category.
- {Fixed Year(Order Date), Sub-Category: Sum(Sales)}
Put this new dimension in the Detail shelf. Drag Sub-Category into the Color shelf as an attribute ATTR(). The key of creating that LOD expression is being able to manipulate each block in every stacked bar.
Click the above image to view the interactive version.
Update 10/12/2020: Over at twitter https://twitter.com/IvettAlexa/status/1315579768734183428?s=20, I just learned there is another approach pre-LOD. Here it is https://kb.tableau.com/articles/howto/sorting-segments-within-stacked-bars-by-value This is a better solution I think.
Update 6/22/2023: A slightly change to the above solution at kb.tableau.com: No ATTR is necessary. Instead, place Region pill in Color under the Combined dimension pill in Detail. It works!
View comments