JSON Conditional formatting in SharePoint Online

Richard Post 21 Reputation points
2021-12-03T09:04:20.97+00:00

Hi All,

I need some help with a simple task in a SharePoint list, but i can't get it right. I have 2 date columns in my list.

1 Customer required date (CCD)
2 Ready For Service date (RFS)

I want to compare the dates and give CCD a red color if RFS is past the CCD or els green. for the KPI measurements. I tried a view JSON solutions but somehow they are comparisons with "@now "

At the moment i am experimenting with the JSON below:

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if(@currentField) >= [$CCD_x0020_Date],'sp-field-severity--severeWarning','sp-field-severity--good')"
},
"children": [
{
"elmType": "span",
"style": {
"display": "inline-block",
"padding": "0 4px"
},
"attributes": {
"iconName": "=if(@currentField >= [$CCD_x0020_Date],'Like','Dislike')"
}
},
{
"elmType": "span",
"txtContent": "@currentField"
}
]
}

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
{count} votes

Answer accepted by question author
  1. Echo Du_MSFT 17,341 Reputation points
    2021-12-06T03:13:15.353+00:00

    Hi @Richard Post

    Welcome to Q&A Forum!

    According to my understanding, your needs are:

    If the RFS is later than the CCD, the CCD is displayed in green and Dislike is displayed;
    If the RFS is earlier than the CCD, the CCD is displayed in red and shows Like;

    For example: CCD is 2021-12-06,
    If the RFS is 2021-12-07, the CCD is green, and the RFS mark is Dislike
    If the RFS is 2021-12-05, the CCD is red, and the RFS mark is Like

    Please use the below JSON formatting for the [CCD Date] column:

    {  
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
    "elmType": "div",  
    "attributes": {  
    "class": "=if(@currentField > [$RFSDate],'sp-field-severity--severeWarning', 'sp-field-severity--good')"  
    },  
    "children": [  
    {  
    "elmType": "span",  
    "style": {  
    "display": "inline-block",  
    "padding": "0 4px"  
    },  
    "attributes": {  
    "iconName": "=if(@currentField >= [$RFSDate],'Like','Dislike')"  
    }  
    },  
    {  
    "elmType": "span",  
    "txtContent": "@currentField"  
    }  
    ]  
    }  
    

    155142-formatting1.jpg

    155143-formatting2.jpg

    155144-formatting3.jpg

    Thanks,
    Echo Du

    ================================

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Richard Post 21 Reputation points
    2021-12-10T07:40:12.177+00:00

    Hi, thanks for all the help! Greetings from the Netherlands

    I have the KPI working with the background color i will check the link for CSS Classes.

    0 comments No comments

  2. The MindFit Admin. Team 0 Reputation points
    2023-01-30T12:48:18.6+00:00

    Hi.

    I have read your article.

    I have one question.

    can you help me?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.