May 19 2023 07:30 AM
I've tried using the following JSON formula to calculate the age according to the date of birth column but ever since I tried adding the formula to my pre-existing list, the age displays as 53. How do I fix this?
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "div", "txtContent": "=floor((Number(@now)-Number([$Birthday]))/(1000*60*60*24*12)/365*12)" }
May 19 2023 08:57 AM
@MelauriePelland sorry, I can't reproduce this; copying & pasting your JSON I get the correct results:
Make sure the Age column is a number column set to no decimal places.
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
May 19 2023 10:19 AM
The age column is set as a number column with no decimal places already. I get this error message when I enter the JSON formula : $ref '/properties/attributes/class' in 'https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json' can not be resolved.(768)
Could that be the reason why it's not working for me?
May 21 2023 11:11 PM
@MelauriePelland If you are using SharePoint online, use below schema in your JSON:
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
Example:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=floor((Number(@now)-Number([$Birthday]))/(1000*60*60*24*12)/365*12)"
}
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
May 23 2023 05:19 AM
@ganeshsanap You do realize you just gave me the exact same JSON I already had?
May 23 2023 05:23 AM - edited May 23 2023 05:25 AM
@MelauriePelland No, look closely at the URLs.
You were using this schema URL:
https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json
and I am asking you to try using this URL instead:
https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json
The first URL/schema is required for SharePoint 2019 and the v2 schema is used for SharePoint online.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
May 23 2023 05:24 AM
May 23 2023 07:08 AM
@MelauriePelland Are you still getting error related to $ref '/properties/attributes/class' after using v2 schema?
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
May 23 2023 07:16 AM
@ganeshsanap Yes, the same error messages appears when using the v2.
Aug 08 2023 06:57 AM
Aug 08 2023 07:21 AM
@Thomasw1964 since my earlier post in this thread I have moved tenant, so I tried it again on a new list but, sorry, I still couldn't reproduce the result of 53, everything was correct:
Rob
Los Gallardos