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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
jitpbi
Post Patron
Post Patron

Change button colour

Hi,

 

I have to dynamically change the colour of a button based on the field's value. The filed has 3 different values 0,1 & 2, please refer the below example:

 

Field ValuesButton Color
0Green
1Orange
2Yellow

 

I had tried through conditional formatting, in the fill color option, but it takes only aggregated value. Please help to achieve this.

 

Thanks

7 REPLIES 7
v-shex-msft
Community Support
Community Support

HI @jitpbi,

You can create a table visual with your records and configure these fields to summarize mode 'do not summarize'.
Then you can apply conditional formatting on 'button color' fields with raw fields values instead of aggregate values.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi, I have tried after configuring the field to summarize mode 'do not summarize' and used conditional formatting in "Fill" option of button but it's not working.

 

My Field has three values : 0,1,2 and i need three different colours for these values.

 

Thanks

amitchandak
Super User
Super User

@jitpbi , You can use color measure, with field option. But I found an issue with slicer color : https://community.powerbi.com/t5/Issues/Field-Conditional-formatting-is-not-working-in-slicer/idi-p/...

Color sales = if(AVERAGE(Sales[Sales Amount])<170,"green","red")
Color Year = if(FIRSTNONBLANK(Table[Year],2014) <=2016,"lightgreen",if(FIRSTNONBLANK(Table[Year],2014)>2018,"red","yellow"))

Color  = if(FIRSTNONBLANK(Table[Year],2014) <=2016 && AVERAGE(Sales[Sales Amount])<170 
,"lightgreen",if(FIRSTNONBLANK(Table[Year],2014)>2018,"red","yellow"))
Color sales = if([Sales Today] -[sales yesterday]>0,"green","red")

color =
switch ( true(),
FIRSTNONBLANK(Table[commodity],"NA") ="commodity1" && sum(Table[Value]) >500,"lightgreen",
FIRSTNONBLANK(Table[commodity],"NA") ="commodity2" && sum(Table[Value]) >1000,"lightgreen",
/// Add more conditions
"red"
)

,

link how to use color measure

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

Hi @amitchandak ,

 

Thank you for the help.

 

I have tried the below measure but it still takes the first value only "#73B761"

 

Measure = SWITCH(TRUE(),FIRSTNONBLANK('Entity State'[State],"NA") = 0,"#73B761", FIRSTNONBLANK('Entity State'[State],"NA") = 1,"#F17925", FIRSTNONBLANK('Entity State'[State],"NA") = 2,"#D9B300").
 
Please let me know if i am doing any mistake here. Also, the field in my dataset has three values 0,1 and 2.
 
Thanks.

Hi, 

 

I have tried with the following measure but it's picking up the green colour only for each value:

 

Measure = SWITCH(TRUE(),FIRSTNONBLANK('Entity State'[State],"NA") = 0,"green",
                                            FIRSTNONBLANK('Entity State'[State],"NA") = 1,"orange",
                                            FIRSTNONBLANK('Entity State'[State],"NA") = 2,"yellow")
 
Thanks,

@jitpbi 


User Field Value in CF under fill color and assign the Measure below, Button Color Field can have actual color name or HEX Codes

_Color = 
VAR _SELECTED = SELECTEDVALUE('Table'[BUTTON COLOR])
RETURN
    _SELECTED

 

 

 

 

Fowmy_0-1595057938028.png

If you are satisfied with my answer, please mark it as a solution so others can easily find it.

Don't forget to give KUDOS to replies that help answer your questions


Subscribe to ExcelFort: Learn Power BI, Power Query and Excel

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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