SOLVED

Display a value in a column with colors based on another column

Copper Contributor

Hello,
I have a list that looks like this:

 

444456464_0-1645441941396.png

I would like to use JSON code so that when the value indicated in the "Lundi" column is greater than that indicated in the "Taux occupation maximal" column, the value of the "Lundi" column is displayed in red, and that if it is lower the value is displayed in green, and if it is equal the value is displayed in orange.

But I can't do that 😞
Can you help me please? Thank you in advance !

6 Replies
Could you create a calculated column to give you true or false and then base the formatting on that?

@Tanya Denton 

No, I have to do something like in the formatting of the Lundi column:
(But this code does not work)

 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "color": "=if(@currentField >[$Tauxoccupationmaximal], '#f00020',''), if(@currentField <[$Tauxoccupationmaximal], '#f008000',''), if(@currentField =[$Tauxoccupationmaximal], '#ff8000','')"
  }
}

 

 

@444456464 Yes I understand that, but you can format the Lundi based on the calculated column (which you can obv hide).  It just another way of achieving what you want if your formatting does not work.

 

2022-02-22_10-05-39.jpg

Oh ok, we can do it like that, but I don't know how to do it :0
best response confirmed by 444456464 (Copper Contributor)
Solution

@444456464 

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

0-SP-list.png

 

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

 

Thank you so much ! 😄
1 best response

Accepted Solutions
best response confirmed by 444456464 (Copper Contributor)
Solution

@444456464 

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

0-SP-list.png

 

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

 

View solution in original post