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 I have a measure called "Don’t feel overstressed" wh...
  • ThomasWeppler's avatar
    9 months ago

    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. 🙂

     

     

     

  • PhilipTreacy's avatar
    9 months ago

    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