Question

I have a Date column in the list and it represents Expiry date.

I need the field to be colored red if the date has passed, orange if the expiry date is less than 30 days, green if the date is more than 30 days.

I have managed to make the formula work, but in the fields where I have no date entered, the field is colored red. I would like to color that field white or not to be colored.

I have tried whit this formula below, but it does not work.

Could someone help me with this please?

{
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if(@currentField <= @now ,'red', if(@currentField <= @now + 2592000000,'orange',if(@currentField == '','white','green')))"
  }
}
Was it helpful?

Solution

You can use Number(DateTimeColumn) == 0 to check if the date column is blank or not.

So try your code like:

{
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if(Number(@currentField) == 0, '', if(@currentField <= @now ,'red', if(@currentField <= @now + 2592000000,'orange',if(@currentField == '','white','green'))))"
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top