Formating Columns using numbers on Lists

Jarryd 1 Reputation point
2022-09-05T05:50:20.537+00:00

Hi, I'm after some assistance in formatting with JSON Code on lists.

I would like to have the colors change according to the value of the column. So the Quantity column changes color based on 2 rules - Rule 1 Red if quantity is less than to the min qty column
rule 2 the quantity column is green if the number is greater than or equal to the number in the min qty column.

Can anyone assist?

237688-image.png

Microsoft 365 and Office | SharePoint | For business | Windows
{count} votes

2 answers

Sort by: Most helpful
  1. Ganesh Sanap 216 Reputation points
    2022-09-05T13:09:41.817+00:00

    Try adding below JSON on Quantity column:

    {  
        "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
        "elmType": "div",  
        "txtContent": "@currentField",  
        "style": {  
            "color": "white",  
            "background-color": "=if(@currentField < [$MinQty], 'red', if(@currentField >= [$MinQty], 'green', ''))"  
        }  
    }  
    

    Use correct internal name of Min Qty field in place of [$MinQty].

    Documentation: SharePoint column formatting

    0 comments No comments

  2. Xuyan Ding - MSFT 7,601 Reputation points
    2022-09-06T07:32:38.727+00:00

    Hi @Jarryd ,

    Does ganesh-sanap's answer help you? Below is the output of my attempt:

    238072-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.


Your answer

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