Forum Discussion

dmann1's avatar
dmann1
Copper Contributor
Jan 06, 2026
Solved

Conditional formatting in lists using JSON condition is between numbers

I'm trying to use JSON to conditional format a color based on the number in the cell.

This code works if the number is one in the cell. I would like to apply the same color if the number is 2 or less and also apply a different color if the number is between 3 and 5. I've tried replacing the "1" above with "=IF (<=2)" and "=IF(@currentField <=2)" with no luck. Thanks

  • dmann1​ you can do this with a shorter json code:

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
      "elmType": "div",
      "txtContent": "@currentField",
      "style": {
        "color": "=if(@currentField <3, 'red', (if(@currentField >= 3 && @currentField <= 5,'orange', 'green'))",
        "padding-left": "15px",
        "font-size": "18px",
        "font-weight": "bold"
      }
    }

     

    Rob
    Los Gallardos
    Principal Consultant, Power Platform, WSP Global (and classic 1967 Morris Traveller driver)

3 Replies

  • Rob_Elliott's avatar
    Rob_Elliott
    Silver Contributor

    dmann1​ you can do this with a shorter json code:

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
      "elmType": "div",
      "txtContent": "@currentField",
      "style": {
        "color": "=if(@currentField <3, 'red', (if(@currentField >= 3 && @currentField <= 5,'orange', 'green'))",
        "padding-left": "15px",
        "font-size": "18px",
        "font-weight": "bold"
      }
    }

     

    Rob
    Los Gallardos
    Principal Consultant, Power Platform, WSP Global (and classic 1967 Morris Traveller driver)

    • dmann1's avatar
      dmann1
      Copper Contributor

      Thanks for the help. It is getting me most of the way there. As your example shows there are three colors. I'll look at your code and try to expand it to five colors to match the five possible answers.

      I did lose the formatting I had that had a pill shape coloring and border around the numbers, but I like just the numbers colored too.

       

      • Rob_Elliott's avatar
        Rob_Elliott
        Silver Contributor

        dmann1​ you can still have pills using a combination of background-color, border and border-radius as shown below:

        {
          "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
          "elmType": "div",
          "txtContent": "@currentField",
          "style": {
            "color": "=if(@currentField <0, 'red', if(@currentField >= 0 && @currentField <= 2,'orange', if(@currentField >2 && @currentField <= 5,'white', if(@currentField > 5 && @currentField <= 10,'blue', 'green'))))",
            "padding-left": "15px",
            "font-size": "18px",
            "border-radius": "25px",
            "background-color": "=if(@currentField <0, 'white', if(@currentField >= 0 && @currentField <= 2,'#483d3b', if(@currentField >2 && @currentField <= 5,'#119cb7', if(@currentField > 5 && @currentField <= 10,'#f5eec9', 'gray'))))",
            "border": "1px solid #bbb"
          }
        }

         


        Rob
        Los Gallardos
        Principal Consultant, Power Platform, WSP Global (and classic 1967 Morris Traveller driver)

Resources