SOLVED

JSON Formatting Referencing Calculated Date Column on SharePoint List

Brass Contributor

I'm hoping someone can help me so I'm not banging my head on the wall trying to find what I think should be a very simple answer.  Basic scenario:

 

I want to color the text in a choice column based on the date shown in a calculated date column. This works perfectly fine when referencing a date column, but not when referencing a calculated date column. It seems the issue is JSON doesn't read the column as a date value and searching extensively on how to have it read it as a date value I can't find anything. Here is an example of the JSON code:

 

{
"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"color": {
"operator": "?",
"operands": [
{
"operator": "<=",
"operands": [
"[$CalculatedDateColumn]",
"@now"
]
},
"#a80000",
""
]
}
}
}

 

It works if the italicized is a date column and I'm guessing there's a way to have JSON treat it as a date column, right?

2 Replies

Making a little bit of progress I thought I had it with coming across the date operator for another use case, but it still doesn't work with the calculated field. This screenshot shows it using a single line text field where it works, but if I change to the calculated column it doesn't. The Phase column is the one that I'm applying the formatting to.

 

Maybe there's a way to specify the calculated value as a string in this same JSON code?

best response confirmed by Jer Harwood (Brass Contributor)
Solution

For anyone else banging their head against the wall trying to get a similar scenario to work I found a solution after coming across this comment in a discussion on GitHub. Changing my calculated column to text instead of date and using the formula to display as a date allows the JSON formatting to "see" the date value to format the Phase column if the date is in the past. My calculated column is looking at multiple date (project phase gates) columns to give the next milestone, but in simple form it works in the attached screenshot.

1 best response

Accepted Solutions
best response confirmed by Jer Harwood (Brass Contributor)
Solution

For anyone else banging their head against the wall trying to get a similar scenario to work I found a solution after coming across this comment in a discussion on GitHub. Changing my calculated column to text instead of date and using the formula to display as a date allows the JSON formatting to "see" the date value to format the Phase column if the date is in the past. My calculated column is looking at multiple date (project phase gates) columns to give the next milestone, but in simple form it works in the attached screenshot.

View solution in original post