SOLVED

Using AND function in column formatting

Copper Contributor

I am trying to create relatively simple conditional column formatting in a SharePoint Online list.

 

This works (the conditions 1==1 and 2==2 are placeholders to simplify the examples here):

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "div",
   "txtContent": "@currentField",
   "style": {
      "color": "=if(1==1, '#ff0000', '#ff00ff')"
   }
}

But when I introduce an AND function, it doesn't work (no formatting occurs):

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "div",
   "txtContent": "@currentField",
   "style": {
      "color": "=if(AND(1==1, 2==2), '#ff0000', '#ff00ff')"
   }
}

What am I doing wrong?

 

2 Replies
best response confirmed by E_Mahn (Copper Contributor)
Solution

@E_Mahn you need to be using && between the 2  criteria of the if statement, for example:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "color": "=if([$FlowHasRun]=='No' && [$Status2]=='Completed' , '#468259', '#c00000')"
  }
}

 

And.png

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User

1 best response

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

@E_Mahn you need to be using && between the 2  criteria of the if statement, for example:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "color": "=if([$FlowHasRun]=='No' && [$Status2]=='Completed' , '#468259', '#c00000')"
  }
}

 

And.png

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User

View solution in original post