Forum Discussion

hgg48's avatar
hgg48
Copper Contributor
Dec 29, 2021

Sharepoint list - highlight a number in column if less than a number in another column

Hi everyone,

 

I'm pretty new to Sharepoint but I've been trying to push myself to use it more. I'm currently creating a list which includes two columns, an On Hand column and a Reorder At column. I would like to format the cells in a way that a cell in the On Hand column would become highlighted if the number within it became equal to or less than the cell in the adjacent column (Reorder At). 

 

So for example, the 2 below should be highlighted since it is less than the 4 to the right.

 

I've been trying to find a way to create a rule in the column formatting to do this but so far am unable to. Any help would be greatly appreciated! Thank you

5 Replies

  • RobElliott's avatar
    RobElliott
    Silver Contributor

    hgg48 you can do this with JSON column formatting. Format the OnHand column, select Advanced Mode and add the following:

     

     

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
      "elmType": "div",
      "txtContent": "@currentField",
      "style": {
        "color": "=if([$OnHand] <= [$ReorderAt], 'red', 'green')",
        "font-weight": "=if([$OnHand] <= [$ReorderAt], 'bold', 'normal')"
      }
    }

     

     

     

    The result is:

     

    Rob
    Los Gallardos
    Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

    • hgg48's avatar
      hgg48
      Copper Contributor

      RobElliottThank you very much for the quick reply, very much so appreciate it. I tried adding what you wrote into the advanced mode editor but the numbers in the OnHand column show up as all green for me. Can you please tell me what I did wrong? Thanks!

      • RobElliott's avatar
        RobElliott
        Silver Contributor

        hgg48 in your list settings check what the internal name is. In my columns I didn't use spaces in the column name - I never do - whereas you might have spaces in your column name. So check that and use the internal column name in your JSON column formatting.

         

         

        Rob
        Los Gallardos
        Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

Resources