Forum Discussion
Set Conditional Formatting Colors Using JSON Theme
During the July 2019 Power BI Desktop update, Amanda Cofsky mentioned that conditional formatting colors could be set using a JSON theme file. She mentions it around the 5:20 mark of this video: https://youtu.be/l7OMRUF9UYg?t=320
Does anyone have the correct code that I could use to add this to my JSON theme?
The September 2019 Power BI Desktop update video had a spot that finally showed the correct syntax to do this!
"maximum": "#00b050",
"center": "#ffff00",
"minimum": "#c00000",
8 Replies
- daxCommunity Support
Hi NickTrent32,
The code in video is correct, you could copy code like below in notepad, then save this as json file, and import this in powerbi, it should work
{ "name": "St Patricks Day", "icons": { "test":{ "url":"https://i.gifer.com/Omjx.gif", "description":"test" } } }Or you also could use gif in conditional format icon directly without importing it. You could try to use measure like below (use this directly by referring to its link)
Icon Set Measure = SWITCH ( TRUE (), [% Change vs Prior Year] < 0, "data:image/svg+xml;utf8, <svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' width='100' height='100' viewBox='0 0 100 100'> <circle cx='50' cy='50' r='40' stroke='purple' stroke-width='4' fill='purple' /> </svg>", [% Change vs Prior Year] < 0.4, "data:image/svg+xml;utf8, <svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' width='100' height='100' viewBox='0 0 100 100'> <circle cx='50' cy='50' r='40' stroke='green' stroke-width='4' fill='yellow' /> </svg>", "https://i.gifer.com/4Ym4.gif" -- "https://i.gifer.com/Omjx.gif" )You could refer to Conditional Formatting Using Icons In Power BI for details.
Best Regards,
Zoe ZhiIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- NickTrent32Advocate II
Sorry dax , I should have been more clear. I would like to set the default Minimum, Center, and Maximum colors in the screenshot below using a JSON theme.
Is that possible?
- daxCommunity Support
Hi NickTrent32,
At first, we can't use custom icon whe you set color conditional format. If you want to set custom color theme, you could try below json
{ "name": "St Patricks Day", "dataColors": ["#568410", "#3A6108", "#70A322", "#915203", "#D79A12", "#bb7711", "#114400", "#aacc66"], "background":"#FFFFFF", "foreground": "#3A6108", "tableAccent": "#568410" }Then you will get below result
If you want to set custom icon based on condition, you could use JSON to import this in report like my irst reply sample, then use this liek below
Or you don't need to import cutsom icon by json, you could use this directly. You could create measure like below
Measure 2 = SWITCH ( TRUE (), [Measure 3]<=5, "https://i.gifer.com/Omjx.gif", [Measure 3] <10, "https://i.gifer.com/KhAg.gif" , "https://i.gifer.com/4Ym4.gif" -- "https://i.gifer.com/Omjx.gif" )You could see coresponding image information in above meaurse, then set cinditional icon like below
Best Regards,
Zoe ZhiIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AnonymousNot applicable
Based on newer updates -
You can set the diverging colors by customising your current theme. Once set, they are your default colors