Conditionally change color based on number value of another column

Occasional Contributor

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.

 

StaffCapacity.png

1 Reply

@Chris Cundy I think you are looking something like this:

Vikram_Samal_1-1590606409603.png

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