Forum Discussion
Dread73
Jul 11, 2024Brass Contributor
JSON Formatting Text to a Choice Pill
Hi Guys, I have a very simple thing I just can't work out how to do. I have a column called Warranty Expiration with a date. I have a Status field with very simple JSON formatting: {
"$sche...
Rob_Elliott
Jul 12, 2024Silver Contributor
Dread73 you can do it with the following JSON (my date column is called Arrival):
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=if(Number([$Arrival]) == 0, '', if([$Arrival] < @now, 'Expired', if([$Arrival] > @now && [$Arrival] < addDays(@now, 30), 'Due Soon', 'Current')))",
"style": {
"background-color": "=if(Number([$Arrival]) == 0, '', if([$Arrival] < @now, 'red', if([$Arrival] > @now && [$Arrival] < addDays(@now, 30), '#f0750f', 'teal')))",
"color": "white",
"box-sizing": "border-box",
"padding": "4px 8px 5px 8px",
"border-radius": "20px"
}
}
Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)
Dread73
Jul 12, 2024Brass Contributor
Awesome Rob_Elliott - that's exactly what I was after! Works like a charm 🙂