I am trying to format this calculated column to show if a number is more than or equal to format it green, or if it is less than or equal to 0 format it red?
-
Do you mean "if a number is greater than 0, format it green and if it is less than or equal to 0, format it red"?– Ganesh SanapDec 5, 2022 at 10:34
-
Hi, yes exactly, I have been trying to find the string and cant get it! :(– MiloDec 5, 2022 at 11:01
-
check my answer given below. let me know if it works for you.– Ganesh SanapDec 5, 2022 at 11:29
1 Answer
Try using this JSON in column formatting option for this column:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"padding-left": "10px"
},
"attributes": {
"class": "=if(@currentField > 0, 'sp-field-severity--good', if(@currentField == 0 || @currentField < 0, 'sp-field-severity--blocked', '') + ' ms-fontColor-neutralSecondary'"
},
"children": [
{
"elmType": "span",
"txtContent": "@currentField.displayValue"
}
]
}
OR
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"padding-left": "10px"
},
"attributes": {
"class": "=if(@currentField > 0, 'sp-field-severity--good', 'sp-field-severity--blocked') + ' ms-fontColor-neutralSecondary'"
},
"children": [
{
"elmType": "span",
"txtContent": "@currentField.displayValue"
}
]
}
Output:
Documentation: Use column formatting to customize SharePoint