Aug 02 2022 07:06 AM
I have a simple list that contains column months and totals. See below:
If any cell is greater than £0 I would like to change the background colour of that cell to red.
How can I achieve this?
Aug 02 2022 07:20 AM
@jonboylib Try using below JSON, it should work for number columns:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"background-color": "=if(@currentField > 0, 'red', '')",
"color": "white"
},
"txtContent": "@currentField"
}
This JSON adds background color of cell as red. You can change the style as per your requirements.
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.
Aug 02 2022 07:22 AM - edited Aug 02 2022 07:30 AM
@ganeshsanap Thanks, where do I add this JSON?
Also, I assume I don't have to add this to every row in my list?
Aug 02 2022 07:48 AM
Aug 02 2022 07:49 AM - edited Aug 02 2022 07:50 AM
Solution@Bharath Arja Thanks.
So, it's not possible to apply this styling to a complete list? If I have 50 columns I need to do this 50 times, manually?
Aug 02 2022 07:58 AM
@jonboylib Yes, you have to add the JSON manually to all the list columns where you want to apply the formatting.
There is a way to update the JSON for each column using PowerShell. But, you must have at least basic experience with PowerShell to loop through list columns & add JSON to required columns. If you are using few columns only, I will suggest to do this manually.
Follow Microsoft official documentation for more information: Column formatting
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.
Aug 02 2022 08:02 AM
@jonboylib If you want to do this using PowerShell, refer below article:
SharePoint Online: Apply Column Format using PowerShell
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.
Aug 02 2022 08:45 AM - edited Aug 02 2022 08:45 AM
@jonboylib I think you have marked the wrong response as best response accidentally.