SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-3197456%22%20slang%3D%22en-US%22%3EDisplay%20a%20value%20in%20a%20column%20with%20colors%20based%20on%20another%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3197456%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3CBR%20%2F%3EI%20have%20a%20list%20that%20looks%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22444456464_0-1645441941396.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F350252iB8EF5E3285F25019%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22444456464_0-1645441941396.png%22%20alt%3D%22444456464_0-1645441941396.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%E2%80%83%3C%2FP%3E%3CP%3EI%20would%20like%20to%20use%20JSON%20code%20so%20that%20when%20the%20value%20indicated%20in%20the%20%22Lundi%22%20column%20is%20greater%20than%20that%20indicated%20in%20the%20%22Taux%20occupation%20maximal%22%20column%2C%20the%20value%20of%20the%20%22Lundi%22%20column%20is%20displayed%20in%20red%2C%20and%20that%20if%20it%20is%20lower%20the%20value%20is%20displayed%20in%20green%2C%20and%20if%20it%20is%20equal%20the%20value%20is%20displayed%20in%20orange.%3C%2FP%3E%3CP%3EBut%20I%20can't%20do%20that%20%3A(%3C%2Fimg%3E%3CBR%20%2F%3ECan%20you%20help%20me%20please%3F%20Thank%20you%20in%20advance%20!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3197456%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3197488%22%20slang%3D%22en-US%22%3ERe%3A%20Display%20a%20value%20in%20a%20column%20with%20colors%20based%20on%20another%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3197488%22%20slang%3D%22en-US%22%3ECould%20you%20create%20a%20calculated%20column%20to%20give%20you%20true%20or%20false%20and%20then%20base%20the%20formatting%20on%20that%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3197546%22%20slang%3D%22en-US%22%3ERe%3A%20Display%20a%20value%20in%20a%20column%20with%20colors%20based%20on%20another%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3197546%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F2552%22%20target%3D%22_blank%22%3E%40Tanya%20Denton%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENo%2C%20I%20have%20to%20do%20something%20like%20in%20the%20formatting%20of%20the%20Lundi%20column%3A%3CBR%20%2F%3E(But%20this%20code%20does%20not%20work)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%22%24schema%22%3A%20%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fcolumn-formatting.schema.json%22%2C%0A%20%20%22elmType%22%3A%20%22div%22%2C%0A%20%20%22txtContent%22%3A%20%22%40currentField%22%2C%0A%20%20%22style%22%3A%20%7B%0A%20%20%20%20%22color%22%3A%20%22%3Dif(%40currentField%20%26gt%3B%5B%24Tauxoccupationmaximal%5D%2C%20'%23f00020'%2C'')%2C%20if(%40currentField%20%26lt%3B%5B%24Tauxoccupationmaximal%5D%2C%20'%23f008000'%2C'')%2C%20if(%40currentField%20%3D%5B%24Tauxoccupationmaximal%5D%2C%20'%23ff8000'%2C'')%22%0A%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3197838%22%20slang%3D%22en-US%22%3ERe%3A%20Display%20a%20value%20in%20a%20column%20with%20colors%20based%20on%20another%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3197838%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1282972%22%20target%3D%22_blank%22%3E%40444456464%3C%2FA%3E%26nbsp%3BYes%20I%20understand%20that%2C%20but%20you%20can%20format%20the%20Lundi%20based%20on%20the%20calculated%20column%20(which%20you%20can%20obv%20hide).%26nbsp%3B%20It%20just%20another%20way%20of%20achieving%20what%20you%20want%20if%20your%20formatting%20does%20not%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%222022-02-22_10-05-39.jpg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F350272i6EFAC8438AA52DE0%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%222022-02-22_10-05-39.jpg%22%20alt%3D%222022-02-22_10-05-39.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3198019%22%20slang%3D%22en-US%22%3ERe%3A%20Display%20a%20value%20in%20a%20column%20with%20colors%20based%20on%20another%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3198019%22%20slang%3D%22en-US%22%3EOh%20ok%2C%20we%20can%20do%20it%20like%20that%2C%20but%20I%20don't%20know%20how%20to%20do%20it%20%3A0%3C%2FLINGO-BODY%3E
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 (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 ! :D