SOLVED

List format question, with an either/or scenario

%3CLINGO-SUB%20id%3D%22lingo-sub-1563275%22%20slang%3D%22en-US%22%3EList%20format%20question%2C%20with%20an%20either%2For%20scenario%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1563275%22%20slang%3D%22en-US%22%3E%3CP%3E1)I%20have%20a%20column%20that%20is%20set%20for%20numbers%2C%20shown%20as%20a%20percentage.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20trying%20to%20format%20the%20column%20where%20if%20I%20type%20into%20the%20field%20%22100%22%2C%20it%20would%20equal%20sp-field-severity--blocked%20and%20if%20I%20type%20%220%22%2C%20it%20would%20equal%20sp-field-severity--good.%20The%20field%20would%20be%20colored%20as%20such.%3C%2FP%3E%3CP%3ESeems%20simple%2C%20but%20I'm%20not%20having%20much%20luck.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2)%20I%20also%20have%20other%20columns%20where%20a%20user%20can%20insert%20text%2C%20but%20only%20one%20answer%20gets%20sp-field-severity--good%20and%20all%20others%20get%20sp-field-severity--blocked.%3C%2FP%3E%3CP%3EI've%20looked%20at%20json%20examples%2C%20but%20as%20usual%2C%20no%20example%20is%20ever%20close%20to%20what%20I%20need.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1563275%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELists%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1567476%22%20slang%3D%22en-US%22%3ERe%3A%20List%20format%20question%2C%20with%20an%20either%2For%20scenario%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1567476%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F495200%22%20target%3D%22_blank%22%3E%40alandarr%3C%2FA%3E%26nbsp%3Bthe%20JSON%20for%20your%20second%20question%20is%20more%20simple.%20In%20this%20example%20if%20the%20user%20enters%20the%20text%20%3CSTRONG%3EChris%3C%2FSTRONG%3E%20then%20the%20background%20is%20green%2C%20otherwise%20it's%20red%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%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%22border%22%3A%20%22none%22%2C%0A%20%20%20%20%22padding-left%22%3A%20%2214px%22%2C%0A%20%20%20%20%22background-color%22%3A%20%22%3Dif(%40currentField%20%3D%3D%20'Chris'%2C%20'%23468259'%2C%20'%23c00000')%22%2C%0A%20%20%20%20%22color%22%3A%20%22white%22%0A%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eand%20the%20result%20is%3A%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22textBackground.png%22%20style%3D%22width%3A%20969px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F210419iDC7D03818091BD7E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22textBackground.png%22%20alt%3D%22textBackground.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERob%3CBR%20%2F%3ELos%20Gallardos%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%20color%3D%22%23006400%22%3EMicrosoft%20Power%20Automate%20Community%20Super%20User.%3CBR%20%2F%3EIf%20I've%20answered%20your%20question%20or%20solved%20your%20problem%2C%20please%20mark%20this%20question%20as%20answered.%20This%20helps%20others%20who%20have%20the%20same%20question%20find%20a%20solution%20quickly%20via%20the%20forum%20search.%20If%20you%20liked%20my%20response%2C%20please%20consider%20giving%20it%20a%20thumbs%20up.%20Thanks.%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1567453%22%20slang%3D%22en-US%22%3ERe%3A%20List%20format%20question%2C%20with%20an%20either%2For%20scenario%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1567453%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F495200%22%20target%3D%22_blank%22%3E%40alandarr%3C%2FA%3E%26nbsp%3Bjust%20looking%20at%20your%20question%201%20for%20the%20moment%20you%20can%20do%20this%20with%20the%20following%20JSON%20column%20formatting.%20In%20this%20example%20if%20the%20value%20you%20enter%20is%20less%20than%20or%20equal%20to%2010%25%20then%20it%20puts%20the%20background%20green%2C%20if%20it's%20between%2011%20and%2050%25%20then%20it's%20orange%2C%20otherwise%20it's%20dark%20red%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%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%3DtoString(%40currentField%20*%20100)%20%2B%20'%25'%22%2C%0A%20%20%22style%22%3A%20%7B%0A%20%20%20%20%22border%22%3A%20%22none%22%2C%0A%20%20%20%20%22padding-left%22%3A%20%2214px%22%2C%0A%20%20%20%20%22background-color%22%3A%20%22%3Dif(%40currentField%20%26lt%3B%3D%200.1%2C'%23468259'%2C%20if(%40currentField%20%26gt%3B%200.1%20%26amp%3B%26amp%3B%20%40currentField%20%26lt%3B%3D%200.5%2C'%23d8a810'%2C%20'%23c00000'))%22%2C%0A%20%20%20%20%22color%22%3A%20%22white%22%0A%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhich%20gives%20the%20following%20result%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22percentBackground.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F210421i1D318D35B28610DE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22percentBackground.png%22%20alt%3D%22percentBackground.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EI%20hope%20that%20gives%20you%20what%20you%20need.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERob%3CBR%20%2F%3ELos%20Gallardos%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%20color%3D%22%23006400%22%3EMicrosoft%20Power%20Automate%20Community%20Super%20User.%3CBR%20%2F%3EIf%20I've%20answered%20your%20question%20or%20solved%20your%20problem%2C%20please%20mark%20this%20question%20as%20answered.%20This%20helps%20others%20who%20have%20the%20same%20question%20find%20a%20solution%20quickly%20via%20the%20forum%20search.%20If%20you%20liked%20my%20response%2C%20please%20consider%20giving%20it%20a%20thumbs%20up.%20Thanks.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1572967%22%20slang%3D%22en-US%22%3ERe%3A%20List%20format%20question%2C%20with%20an%20either%2For%20scenario%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1572967%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F174092%22%20target%3D%22_blank%22%3E%40Rob%20Elliott%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20the%20solution%20to%20my%20first%20question%20and%20it%20worked%20perfectly!%3C%2FP%3E%3CP%3EI%20have%20so%20much%20to%20learn%20with%20these%20lists.%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20so%20for%20taking%20the%20time%20to%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1573101%22%20slang%3D%22en-US%22%3ERe%3A%20List%20format%20question%2C%20with%20an%20either%2For%20scenario%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1573101%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F173457%22%20target%3D%22_blank%22%3E%40Rob%20Elliott%3C%2FA%3E%3CBR%20%2F%3EAgain%2C%20many%20thanks.%20Your%20answer%20to%20my%20second%20question%20is%20spot%20on!%3CBR%20%2F%3EI%20could%20not%20survive%20without%20this%20community!%3C%2FLINGO-BODY%3E
Highlighted
Contributor

 

1) I have a column that is set for numbers, shown as a percentage.

 

I'm trying to format the column where if I type into the field "100", it would color the field red and if I type "0", it would color the field green.

Seems simple, but I'm not having much luck.

 

2) I also have other columns where a user can insert text, but only one answer gets a filed color of green and all others get a field color of red.

 

I've looked at json examples, but as usual, no example is ever close to what I need.

 

Many thanks!

4 Replies
Highlighted
Best Response confirmed by alandarr (Contributor)
Solution

@alandarr just looking at your question 1 for the moment you can do this with the following JSON column formatting. In this example if the value you enter is less than or equal to 10% then it puts the background green, if it's between 11 and 50% then it's orange, otherwise it's dark red:

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=toString(@currentField * 100) + '%'",
  "style": {
    "border": "none",
    "padding-left": "14px",
    "background-color": "=if(@currentField <= 0.1,'#468259', if(@currentField > 0.1 && @currentField <= 0.5,'#d8a810', '#c00000'))",
    "color": "white"
  }
}

 

Which gives the following result:

percentBackground.png

I hope that gives you what you need.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User.
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

 

Highlighted

@alandarr the JSON for your second question is more simple. In this example if the user enters the text Chris then the background is green, otherwise it's red:

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "border": "none",
    "padding-left": "14px",
    "background-color": "=if(@currentField == 'Chris', '#468259', '#c00000')",
    "color": "white"
  }
}

 

and the result is:
textBackground.png

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User.
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

@Rob Elliott 

I tried the solution to my first question and it worked perfectly!

I have so much to learn with these lists. 

Thank you so for taking the time to help.

Highlighted
@Rob Elliott
Again, many thanks. Your answer to my second question is spot on!
I could not survive without this community!