Forum Discussion
Conditional formatting help
- Aug 19, 2022
carlblunck you've missed out the second =
It should be =='Under' etc
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "color": "=if((@currentField > [$Benchmark] && [$Goal]) == 'Under', 'red', if((@currentField < [$Benchmark] && [$Goal]) == 'Over', 'red', 'green')", "font-weight": "=if((@currentField > [$Benchmark] && [$Goal]) == 'Under', 'bold', if((@currentField < [$Benchmark] && [$Goal]) == 'Over', 'bold', 'normal')" } }Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
carlblunck There are multiple problems with your JSON like you have few unnecessary opening brackets, few closing brackets are missing and in expression you need to use double equal to (==) for comparison.
Try this JSON & it should work for you:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"color": "=if(@currentField > [$Benchmark] && [$Goal] == 'Under', 'red', if(@currentField < [$Benchmark] && [$Goal] == 'Over', 'red', 'green'))",
"font-weight": "=if(@currentField > [$Benchmark] && [$Goal] == 'Under', 'bold', if(@currentField < [$Benchmark] && [$Goal] == 'Over', 'bold', 'normal'))"
}
}
Note: You have to use the internal names of columns in JSON in format: [$InternalNameOfColumn].
You can get internal name of columns by following: 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
ganeshsanap I'd already given the JSON code that works fine, even with the extra brackets. Be careful not to step on someone else's solution.
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
- ganeshsanapAug 19, 2022MVP
RobElliott Thank you for your response. Did you actually tried using the JSON you provided?
Try using the JSON you provided & let us know the results. Thank you.
- RobElliottAug 19, 2022Silver ContributorYes I did, as I always do, and it worked perfectly.
- ganeshsanapAug 19, 2022MVP
RobElliott Great, glad it worked for you!
And I am not trying to steal your solution. I replied to this thread only because I observed below problems with the JSON provided by OP in question. Thanks for your understanding, happy weekend!