Conditional formatting based on number of days to due date
Question
In SharePoint 0365, in the modern experience, I have a list of contracts that have an expiration date.
I would like to use conditional formatting to create a status column that shows me the contract is one of these:
- Active, Green background - due date is more than 4 month from today.
- Expiring, Orange background - due date is between 4 month from today and today.
- Expired, Red background - due date is past one day.
I'm trying to get this for while now without success. I matched the formulas in Excell where they're working.
This is the code I'm trying:
{
"elmType": "div",
"style": {
"background-color": "=if([$DueDate] > @now + 1036800000 ,'green', (if([$DueDate] - @now >= 0, '#ffa59b','red'))"
},
"children": [
{
"elmType": "span",
"txtContent": "=if([$DueDate] > @now + 1036800000 ,'Current', (if([$DueDate] >= @now - 10368000000, 'Expiring','Expired'))",
"style": {
"color": "white"
}
}
]
}
And this is the result I get:
Here is the working formula tested in Excel, I'm trying to convert in JSON : =IF(B16>TODAY()+120,"green",IF(B16-TODAY()>=0,"orange","red")) where B16 is the cell containing the contract due date.
Solution
Please try the below and let me know
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=if([$DueDate]>(@now +10368000000), 'Green', if([$DueDate]>@now && [$DueDate]< (@now +10368000000), 'Expiring', 'Expired'))",
"style": {
"background-color": "=if([$DueDate]>(@now +10368000000), 'Green', if([$DueDate]>@now && [$DueDate]< (@now +10368000000), 'Orange', 'Red'))",
"color": "black",
"font-size": "1.5em",
"justify-content": "center"
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange