SharePoint List Header- Column names & calculate number column value not showing

Harry N Nomikos 1,336 Reputation points
2023-09-11T14:59:03.0033333+00:00

Hi Team

I need some help as my column name for Go Live Date isn't showing and the Days till Go Live which is a calculated column isn't showing the number value. Below is how it shows up in my header for a list entry.

User's image

My expected result for my Go Live date should be: Go Live Date: 01/12/2023

My expected result for my Days till Go Live should be: Days till Go Live: 81

Can you please review my JSON coding I've provided below:

Go Live date JSON formula

                    "elmType": "div",
                    "txtContent": "=toLocaleDateString([$GoLiveDate]",
                    "attributes": {
                        "class": "ms-fontColor-white ms-fontWeight-bold ms-fontSize-15"

Days till Go Live formula

                    "elmType": "div",
                    "txtContent": "=if ([$Days_x0020_till_x0020_Go_x0020_L] == '', 'Days till Go Live', 'Days till Go Live: ' + [$Days_x0020_till_x0020_Go_x0020_L])",
                    "attributes": {
                        "class": "ms-fontColor-white ms-fontWeight-bold ms-fontSize-15"

Regards,
Harry

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

Answer accepted by question author
  1. Ling Zhou_MSFT 23,670 Reputation points Microsoft External Staff
    2023-09-14T07:50:35.2533333+00:00

    Hi @Harry N Nomikos,

    Thank you for your reply.

    I apologize that my previous reply was faulty and didn't address your question.

    Here are my results after testing.

    1.Go Live date column

    You can replace the code below:

    {
      "elmType": "div",
      "attributes": {
        "class": "ms-fontColor-white ms-fontWeight-bold ms-fontSize-15"
      },
      "txtContent": "= 'Go Live Date:' + toLocaleDateString([$GoLiveDate])"
    }
    

    2.Days till Go Live column

    I asked my colleague how to calculate the countdown time from a given date to today, and then realized that my previous method was wrong, and that the countdown date is dynamically unchanging.

    Actually, this column need not be a calculated column (and if you are a calculated column you don't have to modify it, the value of the column is not used in JSON formatting), I used the following JSON code to implement the calculation of the countdown days from the date to today for Go Live date column:

    {
      "elmType": "div",
      "attributes": {
        "class": "ms-fontColor-white ms-fontWeight-bold ms-fontSize-15"
      },
      "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)))"
        }
      ]
    }
    

    For this floor(), I have some instructions:

    1.floor((Number([$GoLiveDate])-Number(@now))/(10006060*24)) will take the difference between dates, divide it by duration of a day, and round the final number down to a full number.

    For example: My test today was September 14, 2023 at 3:14pm and the Go Live Date was September 16, 2023. The actual number of days they are apart is: 1.8849 days, but floor() will modify that to 1 day.

    If you think the time error is a bit large, then you can add another day to the end.

    floor((Number([$GoLiveDate])-Number(@now))/(1000*60*60*24))+1

    Here is the result in my side (I just changed the color of the font):

    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.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Ling Zhou_MSFT 23,670 Reputation points Microsoft External Staff
    2023-09-13T03:02:08.0533333+00:00

    Hi @Harry N Nomikos,

    Thank you for your reply.

    1.Go Live date column

    I note that you want to display "Go Live Date: 01/12/2023", but txtContent directly displays the content of the date and does not add “Go Live Date:”

    You can replace the code below:

    {
      "elmType": "div",
      "attributes":{
        "class": "ms-fontColor-white ms-fontWeight-bold ms-fontSize-15"
      }                
      "childern":[
        {
          "elmType":"span",
          "txtContent":"Go Live Date:"
        },
        {
          "elmType": "span",
          "txtContent":"=toLocaleDateString([$GoLiveDate]"
        },
        
      ]                                           
    }
    

    2.Days till Go Live column

    For this column, I am a bit confused about the formula you provided, in SharePoint Calculated columns are not allowed to have Today. If you include Today while creating the Calculated column, then there will be an error and the column will not be created successfully.

    I have created a new date type column named Today in my test environment and set the default value today. Then used this formula in the calculated column: =DATEDIF([Today], [Go Live Date],"d").

    I'm not sure if you're using my way of calculating days, but make sure the values in your column are calculated properly.

    For the JSON of this column, I tested it and found it to be fine, maybe the problem is that the value of that column is calculated wrongly.


    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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.