First time coding with JSON and need a little help...... I am attempting to make a calculated column with conditional formatting. So far i can get it to work but only partially. What i want is to have all cells default to green when empty (basic code), but change color based on the value.....
Basic Code Works
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"style": {
"color": "#ffffff",
"padding-left": "10px",
"background-color": "#0000ff"
},
"children": [{
"elmType": "span",
"txtContent": "$ ",
"style": {
"display": "inline-block",
"padding": "0 1px"
}
},
{
"elmType": "span",
"txtContent": "[$cSDP_x0020_Hardware_x0020_Varian]",
"attributes": {
"class": ""
}
}
]
}
But when i add an if statement the conditions work but the empty cells do not turn green.....
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"style": {
"color": "#000000",
"padding-left": "10px",
"background-color": "= if(@currentField < 0 ,'#CB4335', if(@currentField < ([$cSDP_x0020_Hardware_x0020_Budget] * 0.15) ,'#FFC7CE', if(@currentField < ([$cSDP_x0020_Hardware_x0020_Budget] * 0.3),'#FFEB9C', '#dff6dd'))"
},
"children": [{
"elmType": "span",
"txtContent": "$ ",
"style": {
"display": "inline-block",
"padding": "0 1px"
}
},
{
"elmType": "span",
"style": {
"overflow": "hidden",
"text-overflow": "ellipsis",
"padding": "0 3px"
},
"txtContent": "[$cSDP_x0020_Hardware_x0020_Varian]",
"attributes": {
"class": ""
}
}
]
}
The column/field the formula is evaluating is a calculated number field and I am wondering if that has anything to do with it? I have played around with simple calculations as well and can not seem to even evaluate a value as "0", null, or '' in the if statement.
I have been at this for a few days trying different ways to get it to work and feel i must be missing something simple in the code? I really hope this isn't a stupid SharePoint limitation situation.....
Thanks for your help!
Screenshot #3
if((@currentField == 0) || (@currentField == ''),'#dff6dd', <other conditions here>
. These conditions are totally based on what value you are returning using your calculated formulas. So, change conditions accordingly. Let me know if this works for you.