0

I want the columns with no value in it to be blank. What should I add to my formula?

annotated screenshot illustrating the desired outcome

{   
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "debugMode": true,
  "txtContent": "@currentField",
  "attributes": {
    "class": "=if([$Sovtid_x0020_tekniker_x0020_2] <= @now, 'sp-css-backgroundColor-successBackground50', 'sp-css-backgroundColor-blockingBackground50')"
  }
}
2
  • What is the data type of your column 2nd and 3rd column in screenshot? Or they all are of type Date & Time? – Ganesh Sanap Jan 22 '20 at 12:58
  • They are all Date & time columns! – 288088 Jan 22 '20 at 13:05
1

Try using your JSON code something like below:

{   
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "debugMode": true,
    "txtContent": "@currentField",
    "attributes": {
        "class": "=if(Number(@currentField) != 0, if([$Sovtid_x0020_tekniker_x0020_2] <= @now, 'sp-css-backgroundColor-successBackground50', 'sp-css-backgroundColor-blockingBackground50'), '')"
    }
}

Note:

You can use Number(DateTimeColumn) == 0 to check if the date column is blank or not. This is the major hint, rest you can build the JSON code around it according to your other conditions.

References: Use column formatting to customize SharePoint.

5
  • Sorry, this doesnt work. The fields that should be blank with no background color is now red – 288088 Jan 22 '20 at 13:28
  • You need to add this code in the 2nd and 3rd column in your screenshot where it is having blank fields. where are you adding this JSON code? – Ganesh Sanap Jan 22 '20 at 13:30
  • I'm adding it in all fields. in each column under "Format column". – 288088 Jan 22 '20 at 13:33
  • I have updated the JSON code in my answer. please try it and let me know if this works for you. – Ganesh Sanap Jan 22 '20 at 13:38
  • Thank you, this worked! – 288088 Jan 22 '20 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.