Dec 04 2022 08:30 PM
Hi,
I would like to get automatic age column calculated by today date and date of birth column. I have tried using this method https://techcommunity.microsoft.com/t5/sharepoint/lists-formulas-for-calculate-age-from-date-of-birt...
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=floor((Number(@now)-Number([$DoB]))/(1000*60*60*24*12)/365*12)"
}
Problem is that age column returns value in every role even some rows are blank. How can in fix this issue or there are other method?
Dec 05 2022 02:22 AM - edited Dec 05 2022 02:24 AM
@ppypayap you can add a style section and a visibility attribute to make the number in the age column hidden if the date of birth column doesn't have an entry, for example:
{
"$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)",
"style": {
"background-color": "#008082",
"padding-left": "4px",
"color": "white",
"visibility": "=if(Number[$Birthday]==0,'hidden','visible')"
}
}
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
Jan 23 2023 03:36 AM
Hi @RobElliott is it possible to add to this JSON that if number X is displayed, colour of number is XX, if number Y is displayed, colour of number is YY, if number Z is displayed, colour of number is ZZ
Any help would be appreciated
Jan 23 2023 03:56 AM
@jonna1973 yes you can set the colour depending on the value, for example:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"color": "=if(@currentField <= 8, 'red', (if(@currentField >= 9 && @currentField <= 16,'orange', 'green'))",
"padding-left": "10px"
}
}
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
Jan 23 2023 03:59 AM
Jan 23 2023 05:27 AM
@jonna1973 yes, you'd combine them as follows:
{
"$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)",
"style": {
"background-color": "#c9f2c9",
"color": "=if(floor((Number(@now)-Number([$Birthday]))/(1000*60*60*24*12)/365*12) == 20,'#196958', if(floor((Number(@now)-Number([$Birthday]))/(1000*60*60*24*12)/365*12) == 30, '#ffa900', if(floor((Number(@now)-Number([$Birthday]))/(1000*60*60*24*12)/365*12) == 40, '#a00000', '#b5c2bc')",
"padding-left": "4px",
"visibility": "=if(Number[$Birthday]==0,'hidden','visible')"
}
}
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
Jan 23 2023 05:52 AM