Forum Discussion

Chris Cundy's avatar
Chris Cundy
Copper Contributor
May 27, 2020

Conditionally change color based on number value of another column

Hello, 

 

I have two number columns - "Staff" and "Capacity". I would like the "Capacity" column to conditionally display red if the number on the "Staff" column is 10 less than the number on the "Capacity" column. 

 

For example if "Staff" equals 86 and "Capacity" equals 96, then either the row or the cell on the "Capacity" column should display as red. 

 

I've looked at the basic column formatting but it doesn't appear to have a function to compare between the both.

 

  • Vikram_Samal's avatar
    Vikram_Samal
    Steel Contributor

    Chris Cundy I think you are looking something like this:

    To achieve this you can use the below code:

    {
       "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
       "elmType": "div",
       "txtContent": "@currentField",
       "style": {
          "background-color": "=if([$Staff]<10, '#FFA07A', '')"
       }
    }

    Hopefully this should help. Provide appropriate response if it helps to reach your solution.

     

    Thanks

    Vik

Resources