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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.