I found a great article on color coding a list item based on dates. However, this only works for 2 days within submission. I am trying to have a coding structure that will let me know when something is late. This is the information I am using:

I have a column that subtracts the two dates, then I have another column that uses this script:

="<DIV style='font-weight:bold; font-size:24px; color:"&CHOOSE((IF(SubmissionDateDifference<=2,2,1)),"red","green","orange")&";'>•</DIV>"

With this script, it is only given me the Red and Green colors depending on if the date is greater than 2 days or less than 2 days. I would like to have it give me Red for 0 days and green for greater than 0. When I tried to change the numbers to <=0,0, the formula didn't work.

Also, the final piece in case you were wondering is setting up a web part with the list and below the list is a CEWP with this HTML Script:

<script type="text/javascript">
// Text to HTML
// Demo: sharepoint.infoyen.com by Avinash Kumar Dad
var cellTDs = document.getElementsByTagName("TD");
var i=0;
var TDContent = " ";
while (i < cellTDs.length) {
try {
TDContent = cellTDs[i].innerText || cellTDs[i].textContent;
if ((TDContent.indexOf("<DIV") == 0) && (TDContent.indexOf("</DIV>") >= 0)) {
cellTDs[i].innerHTML = TDContent;
// ExpGroupRenderData overwrites the default SharePoint function
// This part is needed for collapsed groupings
function ExpGroupRenderData(htmlToRender, groupName, isLoaded) {
   var tbody=document.getElementById("tbod"+groupName+"_");
   var wrapDiv=document.createElement("DIV");
   wrapDiv.innerHTML="<TABLE><TBODY id=\"tbod"+ groupName+"_\" isLoaded=\""+isLoaded+ "\">"+htmlToRender+"</TBODY></TABLE>";
   var tBODYTDs = wrapDiv.getElementsByTagName("TD"); var j=0; var cellTDContent = " ";
   while (j < tBODYTDs.length) {
      try {
         cellTDContent = tBODYTDs[j].innerText || tBODYTDs[j].textContent;
         if ((cellTDContent.indexOf("<DIV") == 0) && (cellTDContent.indexOf("</DIV>") >= 0)) {
           tBODYTDs[j].innerHTML = cellTDContent;

The link for this assistance came from


Any assistance will be greatly appreciated.

  • I needed to add a couple of items to this post. This is working inside a library that is pulled from an InfoPath form. Also in my pull for color coding, I would only like it to be red if the date difference is 0 and the status is not = to complete.
    – P BRT
    May 28, 2017 at 3:55

1 Answer 1



in June 2017, Microsoft disabled the use of JavaScript in a Calculated Column

That means given answers may not apply for newer SharePoint versions

For long explanation and work arounds see:
June 13th 2017 Microsoft blocked handling HTML markup in SharePoint calculated fields - how to get the same functionality back

Original answer:

As you see in the first Comment of that Blog you refer to,
that (SP2007 approach) CEWP to convert Calculated Column HTML text to innerHTML
is totally not needed.

Full explanation how to do HTML in Calculated Columns (since SP2010): http://www.viewmaster365.com/#/How

Read all the Cons of this method! and why you should use the Microsoft CSR - Client Side Rendering (since SP2013) method (and do use the WYSYWIG CSR editor Cisar!)

There are multiple answers here on SO doing what you want (with CCs or CSR):

Or even more: https://sharepoint.stackexchange.com/search?q=user%3A32871+due


  • +1 Another that I've found is that REST API for the list can break when calculated columns are present using this hack. Please use XSL, JSLink or other CSR methods--it's so much friendlier to SharePoint.
    – Mike
    May 28, 2017 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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