SharePoint List Header-Conditional Formatting ( Colour Coding) a date field

Harry N Nomikos 1,336 Reputation points
2023-09-21T13:20:20.21+00:00

Hi Team

I have a "Days till Go Live" field in my SharePoint list header that counts how many days are left before it goes live and I was after a formula to colour code the number value based on the below conditions.

If Days till Go Live is 10 days from @now will highlight RED

If Days till Go Live is 20 Days from @now will highlight Orange

If Days till Go Live is 90 Days From @now will highlight Green

Below is my JSON coding that I need amending.

                    "elmType": "div",
                    "attributes": {
                        "class": "ms-fontColor-white ms-fontWeight-bold ms-fontSize-12"
                    },
                    "children": [
                        {
                            "elmType": "span",
                            "txtContent": "=if (Number([$GoLiveDate]) == 0, 'Days till Go Live', 'Days till Go Live: ')"
                        },
                        {
                            "elmType": "span",
                            "txtContent": "=if (Number([$GoLiveDate]) == 0, '',floor((Number([$GoLiveDate])-Number(@now))/(1000*60*60*24)))"

User's image

Regards,
Harry

Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

Accepted answer
  1. Ling Zhou_MSFT 23,620 Reputation points Microsoft External Staff
    2023-09-22T05:29:03.59+00:00

    Hi @Harry N Nomikos,

    I am using header JSON formatting here.

    Please replace the code in your Days till Go Live section with the following JSON:

    {
      "elmType": "div",
      "children": [
        {
          "elmType": "span",
          "attributes": {
            "class": "ms-fontColor-white ms-fontWeight-bold ms-fontSize-12"
          },
          "txtContent": "=if (Number([$GoLiveDate]) == 0, 'Days till Go Live', 'Days till Go Live:')"
        },
        {
          "elmType": "span",
          "attributes": {
            "class": "=if((floor((Number([$GoLiveDate])-Number(@now))/(1000*60*60*24)))<= 10 &&(floor((Number([$GoLiveDate])-Number(@now))/(1000*60*60*24)))>=1 ,'ms-fontColor-red ms-fontWeight-bold ms-fontSize-12',if((floor((Number([$GoLiveDate])-Number(@now))/(1000*60*60*24)))<=30,'ms-fontColor-orangeLighter ms-fontWeight-bold ms-fontSize-12','ms-fontColor-greenLight ms-fontWeight-bold ms-fontSize-12'))"
          },
          "txtContent": "=if (Number([$GoLiveDate]) == 0, '',floor((Number([$GoLiveDate])-Number(@now))/(1000*60*60*24)))"
        }
      ]
    }
    

    Here is the result in my side:

    enter image description here

    User's image

    User's image


    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.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Ling Zhou_MSFT 23,620 Reputation points Microsoft External Staff
    2023-09-22T02:09:26.47+00:00

    Hi @Harry N Nomikos,

    Thank you for posting in this community.

    Please replace the code in your Days till Go Live section with the following JSON:

    {
      "elmType": "div",
      "children": [
        {
          "elmType": "span",
          "attributes": {
            "class": "ms-fontColor-white ms-fontWeight-bold ms-fontSize-12"
          },
          "txtContent": "=if (Number([$GoLiveDate]) == 0, 'Days till Go Live', 'Days till Go Live:')"
        },
        {
          "elmType": "span",
          "attributes": {
            "class": "=if((floor((Number([$GoLiveDate])-Number(@now))/(1000*60*60*24))) == 10,'ms-fontColor-red ms-fontWeight-bold ms-fontSize-12',if((floor((Number([$GoLiveDate])-Number(@now))/(1000*60*60*24))) == 20,'ms-fontColor-orangeLighter ms-fontWeight-bold ms-fontSize-12',if((floor((Number([$GoLiveDate])-Number(@now))/(1000*60*60*24))) == 90,'ms-fontColor-greenLight ms-fontWeight-bold ms-fontSize-12','ms-fontColor-white ms-fontWeight-bold ms-fontSize-12')))"
          },
          "txtContent": "=if (Number([$GoLiveDate]) == 0, '',floor((Number([$GoLiveDate])-Number(@now))/(1000*60*60*24)))"
        }
      ]
    }
    

    Here is the test result in my side:

    enter image description here


    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.


Your answer

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