Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply

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 that even possible?

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

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:

tomfox_0-1647165966033.png

 

 

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:

tomfox_1-1647166436114.png

 

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/

 

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @SalmanABDul_97 

We can make the problem simple with another expression.

When the value is greater than or equal to 75% , return Red . If the value is less than 75% , return Green . Then we can create a measure to return colors .

Outlier = IF([Value]>=0.75,"Red","Green")

Then set conditional formatting for [Value] . Apply measure [Outlier] for [Value] .

Ailsamsft_0-1647324716454.pngAilsamsft_1-1647324716456.png

The final result is as shown :

Ailsamsft_2-1647324716458.png

I have attached my pbix file , you can refer to it .

 

Best Regards

Community Support Team _ Ailsa Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

tackytechtom
Super User
Super User

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:

tomfox_0-1647165966033.png

 

 

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:

tomfox_1-1647166436114.png

 

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/

 

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.