Forum Discussion
Conditional Format SharePoint List Due Dates with three conditions - RAG
- Mar 24, 2021
misce I was recently looking for a similar resource myself. If you are still in need, this code should work for you. If you don't like the exact RAG colors, you can easily replace the them with a different HEX (here is a great site for picking colors: https://hexcolor.co/color-picker)
{"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json","elmType": "div","txtContent": "@currentField","style": {"background-color": "=if(Number(@currentField) == 0, '', if(@currentField >= @now + 2592000000, '#AFF8C9', if(@currentField >= @now + 86400000, '#EEBB2F', if(@currentField <= @now, '#F06C47',''))))"}}
misce I was recently looking for a similar resource myself. If you are still in need, this code should work for you. If you don't like the exact RAG colors, you can easily replace the them with a different HEX (here is a great site for picking colors: https://hexcolor.co/color-picker)
- Lars_Nolmans_-_HoubenMay 17, 2024Copper ContributorFine solution, only I would like to have the font white at background #EEBB2F & #F06C47. I do not succeed
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"background-color": "=if(Number(@currentField) == 0, '', if(@currentField >= @now + 2592000000, '#AFF8C9', if(@currentField >= @now + 86400000, '#EEBB2F', if(@currentField <= @now, '#F06C47',''))))",
"font-weight": "bold",
"padding-left": "15px",
"color": "=if(Number(@currentField) == 0, '',if(@currentField >= @now + 86400000, '#FFFFFF', if(@currentField <= @now, '#FFFFFF',''))"
}
} - SteCoxyNov 26, 2021Copper ContributorThis is exatly what I needed thank you! Would you know how I'd also make the data appear in bold, as well as having the background colours appear?
- ganeshsanapFeb 14, 2024MVP
SteCoxy You can use font-weight parameter for showing text in bold.
Example:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "background-color": "=if(Number(@currentField) == 0, '', if(@currentField >= @now + 2592000000, '#AFF8C9', if(@currentField >= @now + 86400000, '#EEBB2F', if(@currentField <= @now, '#F06C47',''))))", "font-weight": "bold" } }You can also use the similar expression as used for background-color if you want to show the bold text conditionally.
Please consider giving a Like if my post helped you in any way.
- emersonbruceFeb 13, 2024Copper Contributor
SteCoxy add additional items to the Style section based on your desired CSS
- misceApr 21, 2021Copper ContributorUnfortunately I can't get this to work, but I'm going to mark it as correct as it has for someone else so it must just be something I'm doing wrong!
A couple of questions I guess, 1) do I replace @currentField with the name of the column or can I just leave it as that?
I think on second thoughts that my problem may be that the column is a Single Line of Text column, because it's getting data from a PowerApp that was easier at the time, so I'm not sure if it will be possible to do what I wanted anyway.
Thanks for your response! - Maria-ElenaApr 21, 2021Copper Contributor
TKLR_83 Thank you! This worked for me!