I can see that this works in the example. But when I apply this in my actual scenario, it is not working for unknown reasons. I ended up adding five separate expressions (each for each category) in the chart to make it stack.
I'm glad to know that you found the solution you were looking for. If you won't mind and if possible can you please post what exactly worked for you (expressions, settings, etc.) with sample data/app for the help of community.