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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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

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

it works, thank you!

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.

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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