SOLVED

List format question, with an either/or scenario

Brass 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
best response confirmed by alandarr (Brass 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.

 

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

@RobElliott 

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.

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

Accepted Solutions
best response confirmed by alandarr (Brass 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.

 

View solution in original post