Mar 17 2023 03:34 AM - edited Mar 17 2023 04:33 AM
I have a SharePoint list with conditional formatting set up for a specific column which changes the cell background between red and green based on date conditions (see json below).
Next, I would like to automatically fill in the value 'OK' in column 'Status' based on that background in the date cell 'Just nu på datum' is green, and value 'Not OK' in 'Status' if the same date cell is red.
Is this possible and how do achieve that?
Below is the JSON for the conditional formatting:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"padding-left": "10px"
},
"attributes": {
"class": "=if(@currentField <= addDays(@now, -1 * [$M_x00e5_lantalbankdagar]), 'sp-css-backgroundColor-BgCoral sp-css-color-DarkRedText', if(@currentField >= addDays(@now, -1 * [$M_x00e5_lantalbankdagar]), 'sp-css-backgroundColor-BgMintGreen sp-css-borderColor-MintGreenFont', ''))"
}
}
Thanks!
Mar 17 2023 08:06 AM
@magnusjonasson Use this JSON for Status column:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=if(@currentField <= addDays(@now, -1 * [$M_x00e5_lantalbankdagar]), 'Not OK', if(@currentField >= addDays(@now, -1 * [$M_x00e5_lantalbankdagar]), 'OK', ''))"
}
Note: This just displays the value (OK/Not OK) in list view for Status column. It does not actually set the value in Status column.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs
Mar 20 2023 04:42 AM
Mar 20 2023 05:23 AM - edited Apr 17 2023 04:58 AM
@magnusjonasson I forgot to change date column name in JSON conditions in above JSON. Use below JSON instead:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=if([$Justnupadatum] <= addDays(@now, -1 * [$M_x00e5_lantalbankdagar]), 'Not OK', if([$Justnupadatum] >= addDays(@now, -1 * [$M_x00e5_lantalbankdagar]), 'OK', ''))"
}
Use correct internal name of your date column in place of [$Justnupadatum] in above JSON.
Unfortunately, filtering/sorting will not work if you are using JSON to show values.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs
Mar 20 2023 05:25 AM - edited Apr 17 2023 04:59 AM
@magnusjonasson You can follow this article to find out the correct internal name of your date column: Find the internal name of SharePoint column
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs
Mar 20 2023 05:41 AM
Mar 20 2023 05:47 AM
@magnusjonasson Couple of options for this:
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs
Mar 20 2023 05:52 AM
Mar 20 2023 06:04 AM
Solution@magnusjonasson You have to use the calculated column formula in this format:
=IF([Justnupadatum] <= TODAY()-[Malantalbankdagar], "Not OK", IF([Justnupadatum] >= TODAY()-[Malantalbankdagar], "OK", ""))
Here you have to use the display names of columns instead of internal names. Also, if TODAY() does not work, try using NOW().
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs
Mar 20 2023 06:26 AM
Mar 20 2023 06:04 AM
Solution@magnusjonasson You have to use the calculated column formula in this format:
=IF([Justnupadatum] <= TODAY()-[Malantalbankdagar], "Not OK", IF([Justnupadatum] >= TODAY()-[Malantalbankdagar], "OK", ""))
Here you have to use the display names of columns instead of internal names. Also, if TODAY() does not work, try using NOW().
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs