Forum Discussion
soni_b
7 months agoRegular Visitor
Set predefined legend colours using formatting or calculated column for stacked column chart
I'm working with a stacked column chart in Power BI where the legend represents different predefined categories. The challenge I'm facing is that not all categories are present in the current dataset...
- 7 months ago
Hi soni_b,
The key is to ensure all categories exist in your data model, even if they have zero values in the current dataset. Here's how you can try to achieve it:
Create a complete category reference table- Create a new table with all possible categories:
DAXCategoryColors = DATATABLE( "Category", STRING, "ColorCode", STRING, { {"Category 1", "#00FF00"}, {"Category 2", "#FF0000"}, {"Category 3", "#0000FF"}, {"Category 4", "#FFFF00"} } )
- Create a relationship between this table and your fact table
- Use the category from this reference table in your visual's legend
- Set colors manually in Format → Columns - they'll persist even when categories have no data
Best regards!
PS: If you find this post helpful consider leaving kudos or mark it as solution
ryan_mayu
7 months agoSuper User
does that mean your data comes from several data tables? maybe you can create a dim category table and connect it to different data tables and add the category column from dim table to the chart.
if this does not work, pls provide some sample data and expected output.