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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
yodha
Helper IV
Helper IV

Conditional formatting using controls

Hi, am new to power bi, i need help to write a measure for conditioanl formatting, i want to change the colors using controls.

 

need to apply conditional formatting for "%C" column, where values lessthan 50% should be RED in color (back ground color), 51 % to 90% should be YELLOW in color, and anything greater than 90 % should be GREEN in color.

 

Attched sample PBIX for referrence:

https://www.dropbox.com/s/dqt3ggv9zpikl0r/Sample%20report.pbix?dl=0

 

 

Thanks in advance

 

 

 

1 ACCEPTED SOLUTION

@yodhaCreate a measure like this and then use this measure value to conditionally format. You really only need two thresholds - one for red - yellow boundary and the other yellow - red. In any case, you can easily rejig your report to fit this.

 

Measure 3 = 
VAR Avalue = sum('Table'[A])
VAR Bvalue = sum('Table'[B])
VAR pctvalue = DIVIDE(Bvalue, Avalue)*100

RETURN SWITCH(TRUE(),
AND(pctValue > 0, pctvalue <= Red[Red Value]), 0,
AND(pctvalue > Red[Red Value], pctvalue <= Yellow[Yellow Value]), 1,
AND(pctvalue > Yellow[Yellow Value], pctvalue <= Green[Green Value]), 2,
3)

 PBI Help cond formatting 2.PNG

View solution in original post

8 REPLIES 8
parry2k
Super User
Super User

@yodha here you go

 

image.png



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@sanimesa your solution will work but if ever there is % more than 100% which can happen, it will fail. Just a thought.


Cheers!!

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2kGreat! Thanks for the tip!

@parry2k , @sanimesa : Thanks for your response.

but these "%" values are not constant 

(lessthan 50% should be RED in color (back ground color),

51 % to 90% should be YELLOW in color,

and anything greater than 90 % should be GREEN in color). 
These values may change in future.. So for that reason i want to use controls like this, and don't want to use the already existing conditional formatting feature.

 

Capture 1.PNG

Thank you,

 

@yodhaCreate a measure like this and then use this measure value to conditionally format. You really only need two thresholds - one for red - yellow boundary and the other yellow - red. In any case, you can easily rejig your report to fit this.

 

Measure 3 = 
VAR Avalue = sum('Table'[A])
VAR Bvalue = sum('Table'[B])
VAR pctvalue = DIVIDE(Bvalue, Avalue)*100

RETURN SWITCH(TRUE(),
AND(pctValue > 0, pctvalue <= Red[Red Value]), 0,
AND(pctvalue > Red[Red Value], pctvalue <= Yellow[Yellow Value]), 1,
AND(pctvalue > Yellow[Yellow Value], pctvalue <= Green[Green Value]), 2,
3)

 PBI Help cond formatting 2.PNG

@yodha how about to have color in the condition so that it is easy to change and conditional formatting just looking at the field value for the color rather than further conditions in conditional formatting, it is kind of two conditional stuff going on.

 

Measure 3 = 

RETURN SWITCH(TRUE(),
[Your % Measure] >= [Green Value], "Green",
[Your % Measure] >= [Yellow Value], "Yellow",
"Red"
)

 

you can change the above conditions to meet your business logic, and instead of a color name, you can add Hex color code. Now in conditional formatting, choose Field Value

 

image.png

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@sanimesa as a matter of fact, if it is less than 0% in other words, if it is negative %, it will fail there too. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

sanimesa
Post Prodigy
Post Prodigy

@yodhaYou can easily achieve this by choosing conditional formatting on the %C column as shown in the diagram below. Unless there is something else you want - like different shades of green etc. PBI Help cond formatting.PNG

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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