cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
najwakaa
New Member

Sharepoint list JSON column with two conditional

I have two column in sharepoint list. 

Column A is Date & Column B is text

I would like to create a logic where the row will be highlighted to red if Column A is past today date AND Column B is blank. 

I found a code that will help to highlight column A if column B is blank. 

Refer to the picture, and even the future date (the one I circled) is still highlighted. 

However, I could not figure out how add the code to not highlight the date if the due date is not past yet. 

Can anyone help me?

p/s: if possible, how do I color the whole row red instead only the date cell? 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @najwakaa ,

Could you please share a bit more about your scenario?

Do you want to highlight the SP List Row to Red if Column A is past today date AND Column B is blank within your SP list itself?

Further, could you please share a bit more about the formula you used to highlight? Do you use SharePoint column formatting formula to achieve your needs?

 

Based on the needs that you mentioned, I have made a test on my side, and don't have the issue that you mentioned. Please take a try with the following workaround:1.JPGUnder Column Settings, choose Format this column, then click "Advanced mode", type the following formula:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
            "background-color": "=if([$Response]=='' && [$Due_x0020_Date] < @now, '#ff0000', '')"
  }
}

On your side, you should type the following formula:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if([$Response] == '' && [$Date] < @now, '#ff0000', '')"
  }
}

In addition, the SharePoint Column formatting formula only apply to column level rather than row level. If you want to highlight the row to Red if Column A is past today date AND Column B is blank, I afraid that there is no direct way to achieve your needs.

As an alternative solution, you could consider take a try to put above formula within the Column Format Box of all columns in your SP list.

 

More details about the SharePoint column format formula, please check the following article:

https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-xida-msft
Community Support
Community Support

Hi @najwakaa ,

Could you please share a bit more about your scenario?

Do you want to highlight the SP List Row to Red if Column A is past today date AND Column B is blank within your SP list itself?

Further, could you please share a bit more about the formula you used to highlight? Do you use SharePoint column formatting formula to achieve your needs?

 

Based on the needs that you mentioned, I have made a test on my side, and don't have the issue that you mentioned. Please take a try with the following workaround:1.JPGUnder Column Settings, choose Format this column, then click "Advanced mode", type the following formula:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
            "background-color": "=if([$Response]=='' && [$Due_x0020_Date] < @now, '#ff0000', '')"
  }
}

On your side, you should type the following formula:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if([$Response] == '' && [$Date] < @now, '#ff0000', '')"
  }
}

In addition, the SharePoint Column formatting formula only apply to column level rather than row level. If you want to highlight the row to Red if Column A is past today date AND Column B is blank, I afraid that there is no direct way to achieve your needs.

As an alternative solution, you could consider take a try to put above formula within the Column Format Box of all columns in your SP list.

 

More details about the SharePoint column format formula, please check the following article:

https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Thank you. It works. I didn't know that && can work on JSON. I was using the nested if and always get an error. I found that I was using the wrong field name.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (89,060)