1

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?

enter image description here

3
  • 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"? Commented Dec 5, 2022 at 10:34
  • Hi, yes exactly, I have been trying to find the string and cant get it! :(
    – Milo
    Commented Dec 5, 2022 at 11:01
  • check my answer given below. let me know if it works for you. Commented Dec 5, 2022 at 11:29

1 Answer 1

0

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:

enter image description here

Documentation: Use column formatting to customize SharePoint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.