0

Helo. I'm using a SharePoint List to track annual training requirements. I would like for the column to turn a color when the individual is coming up on the 1-year mark, and when they exceed that mark. So, it would be:

365-60 = yellow

365+1 or more = red

Is this possible in SharePoint lists?

2
  • What is the type of the column: date? text? number?
    – jleture
    Commented Sep 6 at 5:13
  • It's a date column.
    – Michael
    Commented Sep 6 at 19:07

2 Answers 2

0

using column formatting with JSON it's possible enter image description here

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
   "background-color": 
   {
      "operator": "?",
      "operands": [
         {
            "operator": ">=",/*if the date is greater than tomorrow  24x60x60x1000 = 86400000 = 1day    */
            "operands": [
               "@currentField",
               {
                  "operator": "+",
                  "operands": [
                     "@now",
                     86400000
                  ]
               }
            ]
         },
         "red",
         {
            "operator": "?",
            "operands": [
               {
                  "operator": "<=",/*if the date is less than today - 60 days*/
                  "operands": [
                     "@currentField",
                     {
                        "operator": "-",
                        "operands": [
                           "@now",
                           5184000000 /* 86400000 x 60 */
                        ]
                     }
                  ]
               },
               "yellow",
               "transparent"
            ]
         }
      ]
   }
}

}

enter image description here

1
  • 1
    Thank you for the answer.
    – Michael
    Commented Sep 6 at 17:03
0

Go to All items -> Format current view -> Advanced mode -> Use following codes.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
  "additionalRowClass": "=if([$Date] < (@now - 5184000000), 'sp-css-backgroundColor-warningBackground50', if([$Date] > @now,'sp-css-backgroundColor-blockingBackground40', ''))"
}

Result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.