Forum Discussion

AnandNamburi's avatar
AnandNamburi
Helper III
4 years ago

How to color code a cell/multiple cells based on a value

Hi All,

 

I have a requirement to color code a cell/multiple cells based a value.

 For example look at the below data:

I want to lookat case number, for same case number if the term/date/casuality is different I need to represent in RED and for the same case number if everything matches no color required.

 

Thanks,

Anand

 

5 Replies

  • I think you can do this by Dax and then put that measure in conditional formating 

    • AnandNamburi's avatar
      AnandNamburi
      Helper III

      Can you suggest me any sample code/approach so that I can try it out.

      • mh2587's avatar
        mh2587
        Super User
        XYZ Color = SWITCH(TRUE(),
                              X < 0,"#FF0000",
                           Y = 0, "#FFFF00",
                         Z >0,       "#00FA9A",
                                        "#00FA7A"          )
  • JirkaZ's avatar
    JirkaZ
    Solution Specialist

    The problem you'll run into though is that the formatting works with the context of current row only. So to create a measure that will look into other cells and rows too, will be pretty difficult. You'll have to be careful to get the correct context for the evaluations.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi AnandNamburi,

    The current power bi conditional formatting feature not support applying to multiple table fields. I think you need to enable multiple color formatting on each field to check the detailed field values.

    formula =
    IF (
        CALCULATE (
            COUNTROWS ( VALUES ( Table[Column] ) ),
            ALLSELECTED ( Table ),
            VALUES ( Table[Case No] )
        ) > 1,
        "Red",
        "Black"
    )

    Notice: replace the 'column' with the field name which you wanted to change the background color.
    Regards,

    Xiaoxin Sheng