Forum Discussion
Conditional Formatting using JSON
I have this code which is working great, however, every time I make a change to add in that if it is blank it should be light coral as well -
here is the original -
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "background-color": "=if((Number([$Emp_x0020_Returns_x0020_OF306]) - Number([$LP_x0020_Sends_x0020_OF306])) / (1000 * 60 * 60 * 24) == 0, 'LightGreen', if((Number([$Emp_x0020_Returns_x0020_OF306]) - Number([$LP_x0020_Sends_x0020_OF306])) / (1000 * 60 * 60 * 24) <= 10, 'LightGreen', if((Number([$Emp_x0020_Returns_x0020_OF306]) - Number([$LP_x0020_Sends_x0020_OF306])) / (1000 * 60 * 60 * 24) >= 11 && (Number([$Emp_x0020_Returns_x0020_OF306]) - Number([$LP_x0020_Sends_x0020_OF306])) / (1000 * 60 * 60 * 24) <= 20, 'LightYellow', if((Number([$Emp_x0020_Returns_x0020_OF306]) - Number([$LP_x0020_Sends_x0020_OF306])) / (1000 * 60 * 60 * 24) > 20, 'LightCoral', '')))", "color": "black", "padding": "5px", "border-radius": "5px" } }
Here is the new attempt at adding in a null value is also Light Coral.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"background-color": "=if(isBlank([$Emp_x0020_Returns_x0020_OF306]) || isBlank([$LP_x0020_Sends_x0020_OF306]), 'LightCoral', if((Number([$Emp_x0020_Returns_x0020_OF306]) - Number([$LP_x0020_Sends_x0020_OF306])) / (1000 * 60 * 60 * 24) <= 10, 'LightGreen', if((Number([$Emp_x0020_Returns_x0020_OF306]) - Number([$LP_x0020_Sends_x0020_OF306])) / (1000 * 60 * 60 * 24) >= 11 && (Number([$Emp_x0020_Returns_x0020_OF306]) - Number([$LP_x0020_Sends_x0020_OF306])) / (1000 * 60 * 60 * 24) <= 20, 'LightYellow', if((Number([$Emp_x0020_Returns_x0020_OF306]) - Number([$LP_x0020_Sends_x0020_OF306])) / (1000 * 60 * 60 * 24) > 20 || isBlank([$Emp_x0020_Returns_x0020_OF306]) || isBlank([$LP_x0020_Sends_x0020_OF306]), 'LightCoral', '')))))",
"color": "black",
"padding": "5px",
"border-radius": "5px"
}
}
It just makes everything transparent. Any help would be highly appreciated! Too bad this isn't built in functionality.