Sharepoint List Conditional column formatting based on date range

Copper Contributor

Hi you clever people,

I am trying to get a DUE DATE column in my list to show red when the BID STATUS is 'Go', and the DUE DATE is within 5 days from now. To test it, we coded it so that it would colour any future dates. However, it's not colouring anything. Here is the code we have:

 

 

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if(((Number([$Submission_x0020_due_x0020_date]) - Number(@now)) > 0) && [$Bid_x0020_status] == 'Go','sp-css-backgroundColor-blockingBackground50', '')"
},
"children": [
{
"elmType": "span",
"style": {
"display": "inline-block",
"padding": "0 4px"
}
},
{
"elmType": "span",
"txtContent": "@currentField"
}
]
}

 

 

  Can anyone advise what we are doing wrong? And why none of the dates are showing red?

 

3 Replies

@MonsoonDesign Try using below JSON code, it should work for you:

 

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "attributes": {
        "class": "=if(([$Submission_x0020_due_x0020_date] >= @now && [$Submission_x0020_due_x0020_date] <= @now + 432000000) && [$Bid_x0020_status] == 'Go', 'sp-css-backgroundColor-blockingBackground50', '')"
    },
    "children": [
        {
            "elmType": "span",
            "style": {
                "display": "inline-block",
                "padding": "0 4px"
            }
        },
        {
            "elmType": "span",
            "txtContent": "@currentField"
        }
    ]
}

 

Make sure you are using correct internal name of Submission due date and Bid status columns.

 

Microsoft documentationUse column formatting to customize SharePoint 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

@ganeshsanap, need help as well. I am looking for JSON code that will highlight the entire row if an item has not been modified for a week.

@royk2022 Use JSON like below in SharePoint JSON view formatting: 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
  "additionalRowClass": "=if([$Modified] < addDays(@now,-7), 'sp-field-severity--severeWarning', '')"
}

 

Make sure you have shown/included Modified column in list view.

Output

ganeshsanap_0-1684481666885.png


Please consider giving a Like if my post helped you in any way.