Forum Discussion

srinivas_fabric's avatar
srinivas_fabric
Regular Visitor
1 year ago
Solved

Adding different Colours for different Row headers in Matrix in Power BI.

I have a matrix visual in Power BI with rows and Columns . I want to add different colours for different row headers. How to do it ?
  • v-menakakota's avatar
    v-menakakota
    1 year ago

    Hi srinivas_fabric,
    Thanks for reaching out to the Microsoft fabric community forum. 

    I recreated the sample data using the screenshot you provided.

    Unpivot the Data
    In Power Query, select the columns 2022, 2023, and 2024, right-click and choose "Unpivot Columns," then rename the resulting columns to Product, Year, and Sales.

    Create a Row Color Measure
    Measure:
    RowColor =

    SWITCH(

        SELECTEDVALUE('Sales'[Product]),

        "Smartphones", "#FFCCCC",        // Light Red

        "Laptops", "#CCE5FF",            // Light Blue

        "Tablets", "#D5F5E3",            // Light Green

        "Headphones", "#FFF2CC",         // Light Yellow

        "Smartwatches", "#E6CCFF",       // Light Purple

        "#FFFFFF"                        // Default White

    )

    Build the matrix by placing Product in Rows, Year in Columns, and adding both Sales and Product to Values (the second Product is for coloring). Then, apply conditional formatting by clicking the dropdown on the second Product field, choosing Conditional formatting > Background color, and setting it to format by field value using the RowColor measure.

    Please go through the screenshot and pbix file for detailed information.


    If I misunderstand your needs or you still have problems on it, please feel free to let us know.   

    Best Regards, 
    Menaka.
    Community Support Team