Forum Discussion

SalmanABDul_97's avatar
4 years ago
Solved

How to add Color using If Statement

My dax forumla is  Outlier = if ([Value] >= [%75] , "Yes" , "NO" )   [%75] is a calculated measure.  what i want is if it yes let the color be Red and if it not let the color be Green.    is t...
  • tackytechtom's avatar
    4 years ago

    Hi SalmanABDul_97 ,

     

    As of my knowledge PBI does not know how to colour code on string values. However, it works just fine if you can provide numbers. So a quick way could be to rewrite your measure like this

    OutlierColourCoding = if ([Value] >= [%75] , 1 , 0 )

     

    Then, use it in the conditional formate pane with this settings:

     

     

    Another way which I personally start to enjoy more and more is to build the colorcodemeasure like this:

    OutlierColourCoding = if ([Value] >= [%75] , "green" , "red" )

     

    or you specify the exact color in Hex:

    OutlierColourCoding = if ([Value] >= [%75] , "#ff0000" , "#66ff33" )

     

    Then you can choose the measure directly to do all the color coding for you:

     

    It goes a lot quicker to set up your color coding on different spots in your report. However, since you are hardcoding the color per value, you are less flexible if you would like to use different colors in different contexts

     

    Does this help? 🙂

     

    /Tom
    https://www.tackytech.blog/
    https://www.instagram.com/tackytechtom/