How do I apply conditional formatting to a row in SharePoint for an upcoming due date?

Tia Hamilton 1 Reputation point
2021-10-08T14:29:10.607+00:00

I need an entire row to change color based on how soon a due date is approaching in a SharePoint list.

Due Date: 12/31/2021

When the due date is:

  • 3 weeks away, I'd like the row to change to yellow.
  • 2 weeks away, orange
  • 1 week away, red

I'm not sure how to make this happen and am not familiar with using json.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,626 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CaseyYang-MSFT 10,321 Reputation points
    2021-10-11T03:19:11.383+00:00

    Hi @Tia Hamilton ,

    Per my test you could use view formatting with if fuction @now keyword to change the row background color based on DueDate.

    Click All items > Format current view > Advanced mode > Type your JSON code > Save

    139266-2.png 139277-3.png

    So here is my JSON codes:

    {  
      "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",  
       "additionalRowClass": "=if([$DueDate] <= @now + 604800000, 'sp-field-severity--severeWarning', if([$DueDate] <= @now + 1209600000, 'sp-field-severity--warning', if([$DueDate] <= @now + 1814400000,'sp-field-severity--good', '')))"  
    }   
    

    My test result:

    139219-1.png

    Note: To use @now keyword, If you want to calculate a week date from now you should add 7 day worth of milliseconds(7*24*60*60*1000 = 604,800,000).So it be like @now + 604800000

    For Reference: Use view formatting to customize SharePoint


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.