Forum Discussion
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 Values | Button Color |
| 0 | Green |
| 1 | Orange |
| 2 | Yellow |
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
- amitchandakSuper 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/1228974#M59165
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-numbers-in-the-column
https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values- jitpbiPost Patron
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,- FowmySuper User
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 _SELECTEDIf 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
- jitpbiPost Patron
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.
- AnonymousNot applicable
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
- jitpbiPost Patron
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
- AnonymousNot applicable
Hi jitpbi ,
For button have a look at this
https://www.youtube.com/watch?v=TVjlf_ucQ6I
https://www.youtube.com/watch?v=oWVMFUle8QU
https://community.powerbi.com/t5/Desktop/Customized-Conditional-Formatting-Using-DAX/td-p/733277
Regards,
Harsh Nathani