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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Giada_Togliatti
Post Patron
Post Patron

dynamic rule for changing color of a measure

Hi, 

 

I need to create a rule for example:

if sum(Sales)>value_1, red,

if value_2<sum(Sales)<value_1, green

if sum(Sales)<value_2, yellow

 

and I need to creare these value_1, value_2 dynamic ( I need to choose them)

how can I do?

 

Thank you

 

Giada

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Giada_Togliatti , Value_1, and Value_2 can be whatif measure

https://docs.microsoft.com/en-us/power-bi/desktop-what-if

 

And you can create a color measure and use option and field and use the measure in conditional formatting

measure= Switch( true(),
sum(Sales)>selectedvalue(value_1[value_1]), "red",
sum(Sales)>selectedvalue(value_[value_2]) && sum(Sales)<selectedvalue(value_1[value_1]), "green",
sum(Sales)>selectedvalue(value_[value_2]), "yellow",
"blue")

https://radacad.com/dax-and-conditional-formatting-better-together-find-the-biggest-and-smallest-num...

https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

Pragati11
Super User
Super User

Hi @Giada_Togliatti ,

 

You can create a measure using following DAX as follows: (Modify it based on the columns and measures you want to use)

 

ColorMeasure =
VAR myEventResult =
SELECTEDVALUE (Table[SALES])
RETURN
SWITCH (
TRUE (),
myEventResult > SUM(Table[SALES]), "#DC5B57",
myEventResult < SUM(Table[SALES]), "#A54441",  "#268361"
)
 
Replace Table[SALES] with your table and column and modify the Hex codes for the colors. Then you can use this measure in conditional formatting.
 
Let me know if this works.
 
If this helps and resolves the issue, appreciate a Kudos and mark it as a Solution! 🙂
 
Thanks,
Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

View solution in original post

4 REPLIES 4
Pragati11
Super User
Super User

Hi @Giada_Togliatti ,

 

You can create a measure using following DAX as follows: (Modify it based on the columns and measures you want to use)

 

ColorMeasure =
VAR myEventResult =
SELECTEDVALUE (Table[SALES])
RETURN
SWITCH (
TRUE (),
myEventResult > SUM(Table[SALES]), "#DC5B57",
myEventResult < SUM(Table[SALES]), "#A54441",  "#268361"
)
 
Replace Table[SALES] with your table and column and modify the Hex codes for the colors. Then you can use this measure in conditional formatting.
 
Let me know if this works.
 
If this helps and resolves the issue, appreciate a Kudos and mark it as a Solution! 🙂
 
Thanks,
Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

amitchandak
Super User
Super User

@Giada_Togliatti , Value_1, and Value_2 can be whatif measure

https://docs.microsoft.com/en-us/power-bi/desktop-what-if

 

And you can create a color measure and use option and field and use the measure in conditional formatting

measure= Switch( true(),
sum(Sales)>selectedvalue(value_1[value_1]), "red",
sum(Sales)>selectedvalue(value_[value_2]) && sum(Sales)<selectedvalue(value_1[value_1]), "green",
sum(Sales)>selectedvalue(value_[value_2]), "yellow",
"blue")

https://radacad.com/dax-and-conditional-formatting-better-together-find-the-biggest-and-smallest-num...

https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

it works, thank you!

MattAllington
Community Champion
Community Champion

Read my blog for how to write the DAX. https://exceleratorbi.com.au/conditional-formatting-with-a-text-field-in-power-bi/

for the selection, you need a What If Parameter



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Kudoed Authors