Forum Discussion
Changing Text Colours Based On Value
Hi,
I have a data set which contains various columns that have "Yes" or "No" values. I have these columns displayed in a table and want the values to change colour.
If the value is "Yes" I want the text colour to change to Red
If the value is "No" I want the text colour to remain black
After browsing around on forums I have found the below Dax and have added it to the conditional format of each column but it is not working. Any ideas on how to achieve this?
Many thanks,
E
Hi Anonymous ,
Your Dax expression doesn't look right. For RED or GREEN color you will have to use HEX COLOR CODES. This is what Power BI understands as colours.
Try creating a measure using following dax:
Colour Change =VAR Dept = SELECTEDVALUE('Safety Valve'[B A])RETURNSWITCH( TRUE(),
Dept = "Yes", "#FF0000",Dept = "No", "#008000"
)You this measure as an conditional formatting in your table visual on your column which has got values YES/NO.You can change the hex color codes as per your requirement.Thanks,Pragati
2 Replies
- Pragati11
Super User
Hi Anonymous ,
Your Dax expression doesn't look right. For RED or GREEN color you will have to use HEX COLOR CODES. This is what Power BI understands as colours.
Try creating a measure using following dax:
Colour Change =VAR Dept = SELECTEDVALUE('Safety Valve'[B A])RETURNSWITCH( TRUE(),
Dept = "Yes", "#FF0000",Dept = "No", "#008000"
)You this measure as an conditional formatting in your table visual on your column which has got values YES/NO.You can change the hex color codes as per your requirement.Thanks,Pragati - amitchandak
Super User
Anonymous , use the measure you created in conditional formatting with "Field" option
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-valuesexample measures
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"))