Forum Discussion

soni_b's avatar
soni_b
Regular Visitor
7 months ago
Solved

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...
  • Mauro89's avatar
    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

    1. Create a new table with all possible categories:
     
    DAX
    CategoryColors = DATATABLE(
        "Category", STRING,
        "ColorCode", STRING,
        {
            {"Category 1", "#00FF00"},
            {"Category 2", "#FF0000"},
            {"Category 3", "#0000FF"},
            {"Category 4", "#FFFF00"}
        }
    )
    1. Create a relationship between this table and your fact table
    2. Use the category from this reference table in your visual's legend
    3. 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