question

TiaHamilton-8509 avatar image
0 Votes"
TiaHamilton-8509 asked YiLu-MSFT commented

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

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.



office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

CaseyYangMSFT-4714 avatar image
0 Votes"
CaseyYangMSFT-4714 answered YiLu-MSFT commented

Hi @TiaHamilton-8509,

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.



2.png (13.9 KiB)
3.png (20.2 KiB)
1.png (7.7 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @TiaHamilton-8509,

I'm checking how the things are going on about this issue, Is there any progress on this issue?

0 Votes 0 ·

Hi @TiaHamilton-8509,

Would you tell me whether your issue has been resolved or have any update? I am looking forward to your reply.

0 Votes 0 ·

Hi @TiaHamilton-8509
Have you tried this code to format the view successfully? Please feel free to reply.

0 Votes 0 ·