Forum Discussion

StuartReeves's avatar
StuartReeves
Copper Contributor
Jan 19, 2022
Solved

JSON conditional formatting for mileages

Hello!   I am trying to code some conditional formatting for a mileage field in sharepoint. I would like the field: - to be green with a tick if the mileage in > 30000 - to be white with an arro...
  • RobElliott's avatar
    Jan 19, 2022

    StuartReeves have a go with the following JSON:

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "attributes": {
        "class": "=if(@currentField >= 3000, 'sp-field-severity--good', if(@currentField < 3000 && @currentField >= 1000, 'sp-field-severity--low',if(@currentField < 1000 && @currentField >= 100, 'sp-field-severity--warning','sp-field-severity--blocked')))"
      },
      "children": [
        {
          "elmType": "span",
          "style": {
            "display": "inline-block",
            "padding": "0 4px"
          },
          "attributes": {
            "iconName": "=if(@currentField >= 3000, 'CheckMark', if(@currentField < 3000 && @currentField >= 1000, 'Forward',if(@currentField < 1000 && @currentField >= 100, 'Error','ErrorBadge')))"
          }
        },
        {
          "elmType": "span",
          "txtContent": "@currentField"
        }
      ]
    }

     

    which results in:

     

     

    Rob
    Los Gallardos
    Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

Resources