Forum Discussion
LearningSharepoint
Oct 23, 2024Copper Contributor
Conditional Formatting for Dates using JSON
Hello, I am trying to use conditional formatting for MS List. I specifically want the background colour of the date to change based upon the number of days over since the file was received. Somet...
- Oct 24, 2024
Otherwise try this (think I found the cause of it, in the code you used):
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "=floor((Number(@now)-Number([$Received]))/86400000)", "style": { "background-color": "=if((floor((Number(@now)-Number([$Received]))/86400000) >= 0 && floor((Number(@now)-Number([$Received]))/86400000) <=30, '#f0f0f0', if((floor((Number(@now)-Number([$Received]))/86400000) > 30 && floor((Number(@now)-Number([$Received]))/86400000) <=60, 'yellow', if((floor((Number(@now)-Number([$Received]))/86400000) > 60 && floor((Number(@now)-Number([$Received]))/86400000) <=90, 'orange','red')", "color": "=if((floor((Number(@now)-Number([$Received]))/86400000) > 90 , 'white', 'black')", "padding-left": "10px" } }
LearningSharepoint
Oct 23, 2024Copper Contributor
Thanks for your response.
I was using the $DateReceived (date) column instead of the $DaysSinceReceived (number). I did this because I couldn't find examples elsewhere that matched my circumstances.
I've added the JSON so the $DaysSinceReceived column and nothing seems to happen. This is my first time adding two sets of JSON code together; do I just plop this underneath the JSON from my other post, or do I need to modify it somehow to work together?
I was using the $DateReceived (date) column instead of the $DaysSinceReceived (number). I did this because I couldn't find examples elsewhere that matched my circumstances.
I've added the JSON so the $DaysSinceReceived column and nothing seems to happen. This is my first time adding two sets of JSON code together; do I just plop this underneath the JSON from my other post, or do I need to modify it somehow to work together?
Hanne_Lauritzen
Oct 24, 2024Iron Contributor
LearningSharepoint My code includes our calculation from the previous post, so already combined the two. So take my new code from my previous reply and replace all of the existing formatting on the DaysSinceRecieved column and you should be good.