Forum Discussion
Adding color in column validation
I've created a custom list in SharePoint online to track our department training. I have a date and time column titled "Expiration" that will list the date that the training/certification will expire. I would like to add a formula to this column that will turn orange once it's 30 days from expiration and then turn red once it's 7 days from expiration. I've searched online and I haven't found a formula that quite matches what I'm looking to do.
I've posted this in the regular SharePoint forum and was advised to post it here.
Thank you.
ChiefKeefe if you wanted to make it stand out a bit more then you could apply the formatting with a background color:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "background-color": "=if([$NextReview] <= @now + 604800000, '#d9184b', if([$NextReview] > @now+604800000 && [$NextReview] <= @now + 2592000000, '#ff9a00','#dddeee')", "color": "white", "padding-left": "10px" } }which gives the following result:
Rob
Los GallardosMicrosoft Power Automate Community Super User
6 Replies
- RobElliottSilver Contributor
ChiefKeefe if you wanted to make it stand out a bit more then you could apply the formatting with a background color:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "background-color": "=if([$NextReview] <= @now + 604800000, '#d9184b', if([$NextReview] > @now+604800000 && [$NextReview] <= @now + 2592000000, '#ff9a00','#dddeee')", "color": "white", "padding-left": "10px" } }which gives the following result:
Rob
Los GallardosMicrosoft Power Automate Community Super User
- ChiefKeefeCopper Contributor
RobElliott and Alireza Rahimifarid Thanks so much for the assistance! I really appreciate it!
- Alireza RahimifaridIron Contributor
Hello,
Please find these two links:
https://microsoft365.today/microsoft-365/column-formatting-to-customize-sharepoint-list/
https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting
And let me know if you need more help.
Alireza
- ChiefKeefeCopper Contributor
Alireza Rahimifarid Thank you. I've already read those two articles prior to reaching out to the community. The part I'm having issues with is integrating a formula. As I stated in my post, I would like to add a formula to this column that will turn orange once it's 30 days from expiration and then turn red once it's 7 days from expiration.
- Alireza RahimifaridIron Contributor
Here is the code:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"color": "=if([$Expiration] <= @now +7 , '#ff0000', '')"
}
}