Forum Discussion

Mohan_Vanku's avatar
Mohan_Vanku
Frequent Visitor
9 months ago
Solved

dynamic conditional formatting

Hi everyone

I am trying to apply conditional formatting in a Matrix visual in Power BI based on a KPI measure.

Here is what I want to achieve

  1. I have a measure called "Don’t feel overstressed" which gives my KPI value dynamically.

  2. I want to apply conditional formatting to the Matrix such that

    • From 0 to the half of KPI value  → Red color (low performance)

    • Half from KPI value to the KPI value → Green color (approaching target)

    • Above the KPI value → White color

  3. The KPI value changes over time, so I want these thresholds and colors to adjust dynamically based on the current KPI value.

  • Add a DAX code
    Don’t feel overstressed color =
    IF (
        [meassure] >= 0 && [meassure] < DIVIDE ( [Don't feel overstressed], 2 ),
        1,
        IF (
            [meassure] >= DIVIDE ( [Don't feel overstressed], 2 )
                && [meassure] < [Don't feel overstressed],
            2,
            3
        )
    )

    Then

    Choose the KPI in your matrix and press the arrow down. then go to conditional formatting and pick bagground color.

     

     

     

     

    Pick the format style rules and add 2 new rules then pick the color you want when [Don’t feel overstressed color] has the value 1, 2 and 3

    I hope this help. 🙂

     

     

     

  • Hi Mohan_Vanku 

     

    Download example PBIX with the code and data shown below

     

    You can create a measure that generates the hex color code based on your rules about the values in relation to the Don't feel overstressed measure :

     

    Matrix CF = 
    
    SWITCH( TRUE(),
    
    [Sale inc Tax] > [Don't feel overstressed], "#FFF", //WHITE
    
    [Sale inc Tax] > [Don't feel overstressed] / 2, "#0F0", //GREEN
    
    "#F00" //RED
    )

     

    Then you select Conditional Formatting -> Backgroudn color from the drop down menu for the matrix values (note that I'm obviously using my own dummy data here)

     

     

    In the CF settings, choose Format style -> Field value and then choose the measure just created Matrix CF as the field to decide the colors, click OK

     

     

    You should see something like this.  I've given the KPI an arbitrary value of 5

     

     

    Regards

     

    Phil

     

4 Replies

  • ThomasWeppler's avatar
    ThomasWeppler
    Impactful Individual

    Add a DAX code
    Don’t feel overstressed color =
    IF (
        [meassure] >= 0 && [meassure] < DIVIDE ( [Don't feel overstressed], 2 ),
        1,
        IF (
            [meassure] >= DIVIDE ( [Don't feel overstressed], 2 )
                && [meassure] < [Don't feel overstressed],
            2,
            3
        )
    )

    Then

    Choose the KPI in your matrix and press the arrow down. then go to conditional formatting and pick bagground color.

     

     

     

     

    Pick the format style rules and add 2 new rules then pick the color you want when [Don’t feel overstressed color] has the value 1, 2 and 3

    I hope this help. 🙂

     

     

     

  • Hi Mohan_Vanku 

     

    Download example PBIX with the code and data shown below

     

    You can create a measure that generates the hex color code based on your rules about the values in relation to the Don't feel overstressed measure :

     

    Matrix CF = 
    
    SWITCH( TRUE(),
    
    [Sale inc Tax] > [Don't feel overstressed], "#FFF", //WHITE
    
    [Sale inc Tax] > [Don't feel overstressed] / 2, "#0F0", //GREEN
    
    "#F00" //RED
    )

     

    Then you select Conditional Formatting -> Backgroudn color from the drop down menu for the matrix values (note that I'm obviously using my own dummy data here)

     

     

    In the CF settings, choose Format style -> Field value and then choose the measure just created Matrix CF as the field to decide the colors, click OK

     

     

    You should see something like this.  I've given the KPI an arbitrary value of 5

     

     

    Regards

     

    Phil

     

  • v-priyankata's avatar
    v-priyankata
    Community Support

    Hi Mohan_Vanku 

    Thank you for reaching out to the Microsoft Fabric Forum Community.

    PhilipTreacy ThomasWeppler Thanks for the inputs.

    I hope the information provided by users was helpful. If you still have questions, please don't hesitate to reach out to the community.

     

    • v-priyankata's avatar
      v-priyankata
      Community Support

      Hi Mohan_Vanku 

      Hope everything’s going smoothly on your end. I wanted to check if the issue got sorted. if you have any other issues please reach community.