Comparing values in Sharepoint list, from two columns and conditional format result

Drinkwalter, Lisa 21 Reputation points
2022-07-01T22:13:16.483+00:00

I can't seem too find the right JSON code for a Sharepoint 365 list to compare two columns' values with conditional formatting. Trying to compare a Monthly Target number with actual Monthly number achieved, making the Monthly number red, green or yellow depending on criteria. Sharepoint lists don't allow the second column to be selected as a comparison...just a value.

I tried finding a JSON code, but no luck. I tried creating a calculated column that would return a colour, but I don't know what code to put in.

Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

Accepted answer
  1. Yi Lu_MSFT 17,611 Reputation points
    2022-07-04T09:57:58.877+00:00

    Hi @Drinkwalter, Lisa
    If you just want to make the Monthly number red, green or yellow depending on criteria, you could use column formatting: column settings > format this column >Advanced

    217346-image.png

    217269-image.png

    Then copy the code into it:

    {   
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
      "elmType": "div",  
      "txtContent": "=toString((@currentField)*100)+'%'",  
      "style": {  
        "color": "=if([$MonthlyTargetnumber] <(@currentField),'red','green')"  
      }  
    }  
    

    This is the result:
    218206-image.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Drinkwalter, Lisa 21 Reputation points
    2022-07-04T13:51:38.847+00:00

    @Yi Lu_MSFT - thanks for responding...still having some issues.

    Would like anything below target to be red

    Would like anything equal to or above target to be green

    If possible, would like to show in percent (it changes the formatting when I paste the code in)

    Currently it is showing all numbers red.

    Appreciate your help.
    Thank you,
    Lisa

    217423-image.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.