SharePoint Column Formatting

Tanvir, Abdullah (Contractor) 1 Reputation point
2020-09-14T12:52:54.233+00:00

Hi Everyone,

I have applied column formatting to my Year's column. Whenever the year entered is two years before the current year the color of the cell should turn to red. But when there is no entry into the year still the cell color is turned into red.

Below is the JSON code:

{

"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",

"elmType": "div",

"style": {

"background-color": "=if([$Year] < getYear(@now)-1, '#FFA07A','')",

"box-sizing": "border-box",

"padding": "4px 8px 5px 8px",

"display": "flex",

"border-radius": "16px",

"height": "24px",

"align-items": "center",

"white-space": "nowrap",

"overflow": "hidden",

"margin": "4px 4px 4px 4px"

},

"debugMode": true,

"txtContent": "@currentField"

}

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,270 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,021 Reputation points
    2020-09-15T02:01:11.92+00:00

    Hi @Tanvir, Abdullah (Contractor)

    Change your json code to this:

    "background-color": "=if([$Year] < getYear(@now)-1, if([$Year]=='','','#FFA07A'),'')",  
    

    Test:

    24752-image.png


    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.

    0 comments No comments