KPI Dashboard using SharePoint List

We can generate the KPI list using simple SharePoint list with computed columns! Here is how we can get SharePoint list based status indicator.

KPI Dashboard using SharePoint List

Create a SharePoint list with desired fields, then create a field with choices, Let’s say, Field name Cost_Input: with values Red, Green, Blue. Then let’s create another computed field called Cost of type: Number, which is based on the existing field COST_Input field.

Enter the formula for the calculated field as:

=IF(Cost_input=”Green”,”<DIV style=’text-align: center’><IMG src=’/_layouts/images/KPIDefault-0.gif’/></DIV>”,IF(Cost_input=”Yellow”,”<DIV style=’text-align: center’><IMG src=’/_layouts/images/KPIDefault-1.gif’/></DIV>”,IF(Cost_input=”Red”,”<DIV style=’text-align: center’><IMG src=’/_layouts/images/KPIDefault-2.gif’/></DIV>”)))

Then after adding the content editor web part exactly after the list web part, then add the below code snippet in the source editor of the content editor web part.


<script type="text/javascript">
//
// Text to HTML
//
var theTDs = document.getElementsByTagName("TD");
var i=0;
var TDContent = " ";
while (i < theTDs.length) {
try {
TDContent = theTDs[i].innerText || theTDs[i].textContent;
if ((TDContent.indexOf("<DIV") == 0) && (TDContent.indexOf("</DIV>") >= 0)) {
theTDs[i].innerHTML = TDContent;
}
}
catch(err){}
i=i+1;
}
//
// 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 theTBODYTDs = wrapDiv.getElementsByTagName("TD"); var j=0; var TDContent = " ";
while (j < theTBODYTDs.length) {
try {
TDContent = theTBODYTDs[j].innerText || theTBODYTDs[j].textContent;
if ((TDContent.indexOf("<DIV") == 0) && (TDContent.indexOf("</DIV>") >= 0)) {
theTBODYTDs[j].innerHTML = TDContent;
}
}
catch(err){}
j=j+1;
}
tbody.parentNode.replaceChild(wrapDiv.firstChild.firstChild,tbody);
}
</script> 

Update: For SharePoint 2013, Use the below code in Script editor:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
 <script type="text/javascript">
     //load jQuery
     google.load("jquery", "1.2.6");
 </script>
 <script type="text/javascript">
 //make a fn for reuse
 $.calcHTML = function() {
     //loop through TDs moving text node to html
     $("td.ms-vb2,td[id$='Calculated'],td.ms-stylebody,td.ms-formbody").filter(":contains(<DIV)").each(function(){
         $(this).html($(this).text());
     });
 };
 //call calcHTML on DOM ready for ungrouped rows
 $(function() {
     $.calcHTML();
     if (showpreview1) { //check for preview script
         $("td.ms-vb-title").bind("mouseover", function(){
             showpreview1(this);
             $.calcHTML();
         });
     }
 });
 //replace ExpGroupRenderData, call calcHTML for grouped rows
 function ExpGroupRenderData(htmlToRender, groupName, isLoaded) {
     $("#tbod"+groupName+"_").attr("isloaded",isLoaded).html(htmlToRender).show("fast",$.calcHTML());
 }
 </script>

Alternate approach: Using Dataview web part to Design KPI Dashboard

Same thing can be achieved using SharePoint Designer & Dataview web part. Just convert the existing List view to XSLT Dataview and set the conditional formatting as in below images.

Set the conditional formatting style:

sharepoint dataview kpi

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

8 thoughts on “KPI Dashboard using SharePoint List

  • Hi,

    the updated code for SP2013 doesn’t work for me (on SP 2013), because in Line 1 there are a lot of SPAN tags. Seems like a copy paste error? Without these tags, everything looks fine is fine.

    Many thanks for this elegant solution and setup instructions!

    Reply
  • hello,

    when i use the group by in my list view it doesn’t work, any idea?

    Reply
  • Hi Salaudeen,

    Thank you so much for sharing this great solution.

    We are using SharePoint Online.

    We followed the steps listed above with the list and code added to Script Editor.

    We tried it with Cost Column, instead of displaying the KPI icon, the code in the formula shows up.

    Please could you kindly advise what went wrong?

    Thank you very much for your kind help.

    Charlotte Tang

    Reply
  • Thanks a lot Salaudeen, this is what I was exactly looking for!
    Just a doubt, is it possible to display the KPI with a value next to it? I tried with the symbol “&” or with the formula “CONCATENATE”, but then it converts the html to pure text and it doesn’t display the traffic light.

    Reply
    • Chris,
      That’s where the jQuery comes to the picture. It just converts Text to HTML. Place the jQuery provided above!

      Reply
  • hello
    Great article.
    I have made this work fine, but my next step is to join 8 of them together.
    I.E. I have 8 columns now all with images. R1, R2 R3 etc.
    If i make anotyher calcultaed column with =R1&R2&R3 i get them together, but they are verticle not horizontal.
    Do you have a solution for this please?
    Regards
    Clayton

    Reply
    • Clayton,
      You can’t use values from different rows in calculated columns! If you must do that, You have to write XSL!!

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *