{"id":506,"date":"2013-11-27T01:11:31","date_gmt":"2013-11-27T01:11:31","guid":{"rendered":"http:\/\/order-out-of-chaos.net\/?p=506"},"modified":"2015-04-11T16:56:05","modified_gmt":"2015-04-11T16:56:05","slug":"creating-custom-key-performance-indicators-with-calculated-columns-in-sharepoint-2013","status":"publish","type":"post","link":"https:\/\/themercers.ca\/OrderOutOfChaos\/creating-custom-key-performance-indicators-with-calculated-columns-in-sharepoint-2013\/","title":{"rendered":"Creating custom Key Performance Indicators with calculated columns in SharePoint 2013"},"content":{"rendered":"<h2>Creating Custom Key Performance Indicators with Calculated Columns<\/h2>\n<p><b>Consider the following scenario<\/b><br \/>\nA team wants to be able to prioritize their work so they can visually see what are the most important items to focus on. They will use low, medium and high priorities, represented by yellow, orange and red images.<\/p>\n<p><b>Things You Need<\/b><\/p>\n<ul>\n<li>Custom indicator images for as many levels as you require.<\/li>\n<li>Text to HTML JavaScript<\/li>\n<li>A custom list<\/li>\n<li>A choice type column in the list<\/li>\n<li>A calculated column in the list<\/li>\n<li>A web part containing the Text to HTML script<\/li>\n<\/ul>\n<h3>Step 1 \u2013 Get the Images<\/h3>\n<p><b>Instructions:<\/b><\/p>\n<p>Go to Icon Finder (<a href=\"https:\/\/www.iconfinder.com\/\">https:\/\/www.iconfinder.com\/<\/a>) and do a search for the kind of icons you want. In this case we\u2019ll search for \u201csquare icon\u201d and choose a glossy orange square at 24&#215;24 pixels and download it to our PC. Then we\u2019ll look for yellow and red in the same theme set and download those as well. The images tend to come with weird filenames so we\u2019ll rename them to something more user friendly such as: \u201cicon-yellow.png\u201d, \u201cicon-orange.png\u201d and \u201cicon-red.png\u201d.<\/p>\n<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/yellow-24.png\" alt=\"yellow-24\" width=\"24\" height=\"24\" \/>  <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/orange-24.png\" alt=\"orange-24\" width=\"24\" height=\"24\" \/>  <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/red-24.png\" alt=\"red-24\" width=\"24\" height=\"24\" \/><\/div>\n<p><b>NOTE: <\/b>It is important to find images that are in the Portable Network Graphic (PNG) format because they have transparent backgrounds and will look good in any theme.<\/p>\n<h3>Step 2 \u2013 Upload the Images to SharePoint<\/h3>\n<p>Next we\u2019ll need to upload the images into SharePoint. SharePoint 2013 sites come with a built in library called \u201cSite Assets\u201d and it is highly recommended to store the images in this location.<\/p>\n<p><b>Instructions:<\/b><\/p>\n<p>Click on the Site Contents link and the click on the Site Assets library.<br \/>\nClick on new document and upload each image from your PC.<\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-images.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-510\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-images.png\" alt=\"add-images\" width=\"480\" height=\"331\" \/><\/a><\/p>\n<h3>Step 3 \u2013 Create the Text to HTML Script<\/h3>\n<p>The following script is available from <strong>Christophe Humbert<\/strong> (Blog Path to SharePoint: <a href=\"http:\/\/blog.pathtosharepoint.com\/\">http:\/\/blog.pathtosharepoint.com\/<\/a>). This has been tested and confirmed to work with SharePoint 2013.<\/p>\n<p><b>Instructions:<\/b><br \/>\nTake the following code and paste it into a new text file (using Notepad or another text editor) and save it as \u201cTexttoHTMLSP013.txt\u201d.<\/p>\n<pre><b>&lt;script type=\"text\/javascript\"&gt;<\/b>\r\n <b>\/\/ Copyright (c) 2010 Christophe Humbert - Path to SharePoint<\/b>\r\n <b>\/\/ Find all Web Parts in the page<\/b>\r\n <b>var listWP=[],calWP=[],divs=document.getElementById(\"DeltaPlaceHolderMain\").getElementsByTagName(\"div\");<\/b>\r\n <b>var count=divs.length;<\/b>\r\n <b>for (i=0;i&lt;count;i++) {<\/b>\r\n <b>try {<\/b>\r\n <b>if (divs[i].id.indexOf(\"WebPartWPQ\")==0){<\/b>\r\n <b>if (divs[i].innerHTML.indexOf(\"ViewDefault_CalendarView\")&gt;=0) {<\/b>\r\n <b>\/\/ Calendars<\/b>\r\n <b>calWP.push(divs[i].id);<\/b>\r\n <b>}<\/b>\r\n <b>else {<\/b>\r\n <b>\/\/ Other Web Parts<\/b>\r\n <b>listWP.push(divs[i].id);<\/b>\r\n <b>}<\/b>\r\n <b>}<\/b>\r\n <b>}<\/b>\r\n <b>catch(e){}<\/b>\r\n <b>}<\/b>\r\n <b>function TextToHTML(NodeSet, HTMLregexp) {<\/b>\r\n <b>var CellContent = \"\";<\/b>\r\n <b>var i=0;<\/b>\r\n <b>while (i &lt; NodeSet.length){<\/b>\r\n <b>try {<\/b>\r\n <b>CellContent = NodeSet[i].innerText || NodeSet[i].textContent;<\/b>\r\n <b>if (HTMLregexp.test(CellContent)) {NodeSet[i].innerHTML = CellContent;}<\/b>\r\n <b>}<\/b>\r\n <b>catch(err){}<\/b>\r\n <b>i=i+1;<\/b>\r\n <b>}<\/b>\r\n <b>}<\/b>\r\n <b>var regexpA = new RegExp(\"\\s*&lt;([a-zA-Z]*)(.|\\s)*\/\\1?&gt;\\s*$\");<\/b>\r\n <b>var regexpTD = new RegExp(\"^\\s*&lt;([a-zA-Z]*)(.|\\s)*\/\\1?&gt;\\s*$\");<\/b>\r\n <b>var WP = new Object;<\/b>\r\n <b>function UpdateWP() {<\/b>\r\n <b>if (calWP.length&gt;0){<\/b>\r\n <b>for (i=0;i&lt;calWP.length;i++) {<\/b>\r\n <b>WP=document.getElementById(calWP[i]);<\/b>\r\n <b>if (WP.innerHTML.indexOf(\"&amp;lt;\")&gt;=0) {TextToHTML(WP.getElementsByTagName(\"a\"),regexpA);}<\/b>\r\n <b>}<\/b>\r\n <b>}<\/b>\r\n <b>if (listWP.length&gt;0){<\/b>\r\n <b>for (i=0;i&lt;listWP.length;i++) {<\/b>\r\n <b>WP=document.getElementById(listWP[i]);<\/b>\r\n <b>if (WP.innerHTML.indexOf(\"&amp;lt;\")&gt;=0) {TextToHTML(WP.getElementsByTagName(\"td\"),regexpTD);}<\/b>\r\n <b>}<\/b>\r\n <b>}<\/b>\r\n <b>\/\/ Check every 200 ms, forever<\/b>\r\n <b>setTimeout(\"UpdateWP()\",200);<\/b>\r\n <b>}<\/b>\r\n <b>UpdateWP();<\/b>\r\n <b>&lt;\/script&gt;<\/b><\/pre>\n<h3>Step 4 \u2013 Upload the Text to HTML Script<\/h3>\n<p>Now let\u2019s upload the TexttoHTMLSP013.txt file to the Site Assets library just we did with the images in Step 2.<\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-script.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-515\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-script.png\" alt=\"add-script\" width=\"517\" height=\"349\" \/><\/a><\/p>\n<h3>Step 5 \u2013 Create a new Custom List<\/h3>\n<p>Next we need to create a custom list (via the Add an app feature in SharePoint 2013) that will have our custom images used in.<\/p>\n<p><b>Instructions:<br \/>\n<\/b>Click on the settings \u201cCog\u201d and then select \u201cAdd an app\u201d.<\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-an-app.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-516\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-an-app.png\" alt=\"add-an-app\" width=\"168\" height=\"299\" \/><\/a><\/p>\n<p>Next, let\u2019s select the Custom List type and then name it \u201cVisualWork\u201d (of course in practice you can name it whatever you want).<\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/create-custom-list.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-517\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/create-custom-list.png\" alt=\"create-custom-list\" width=\"800\" height=\"319\" \/><\/a><\/p>\n<p><b>NOTE:<\/b> If you create a name with white space in it (e.g.: Visual Work), the URL will end up with extra characters in it (e.g.: \u2026\/Visual%20Work.aspx). This is due to the fact that web addresses cannot contain whitespace so the white spaces are rendered with a \u201c%20\u201d instead of a blank space. Furthermore once a URL has been created in SharePoint is it permanent. The title and description can be modified after creation by the URL cannot. So if you create a list with white space in the name it cannot be undone.<\/p>\n<h3>Step 6 \u2013 Create a new Choice type Column in the List<\/h3>\n<p>Next we need to create a choice column which we will use to calculate against. In this case we\u2019ll create a new choice column called \u201cPriority\u201d and then give it three choices: Low, Medium and High.<\/p>\n<p><b>Instructions:<br \/>\n<\/b>Click on the ribbon and then List&gt;List Settings&gt;<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/list-settings.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-518\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/list-settings.png\" alt=\"list-settings\" width=\"713\" height=\"173\" \/><\/a><\/p>\n<p><b>Create Column<\/b><\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/create-column.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-519\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/create-column.png\" alt=\"create-column\" width=\"628\" height=\"326\" \/><\/a><br \/>\nColumn Name: <b>Priority <\/b><br \/>\nColumn Type: <b>Choice<\/b><br \/>\nType each choice on a separate line:<br \/>\n<b>Low<\/b><br \/>\n<b>Medium<\/b><br \/>\n<b>High<\/b><\/p>\n<p>Then click <b>OK<\/b>.<\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/create-priority.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-520\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/create-priority.png\" alt=\"create-priority\" width=\"584\" height=\"738\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Step 7 \u2013 Create a new Calculated type Column in the List<\/h3>\n<p>Now we need to create a calculated column which we will use to show the images based on what is selected in the choice column.<br \/>\nIn this case we\u2019ll create a new calculated column called \u201cIndicator\u201d and then give it three possible calculations. The calculation will be if Priority is equal to Low then show a yellow image, if Priority is equal to Medium then show an orange image and finally, if Priority is equal to High then show a red image.<\/p>\n<p><b>Instructions:<br \/>\n<\/b>Click on the ribbon and then <b>List<\/b>&gt;<b>List Settings<\/b>&gt;<b>Create Column<\/b>&gt;<br \/>\nColumn Name: <b>Indicator<\/b><br \/>\nColumn Type: <b>Calculated<\/b><br \/>\nFormula:<\/p>\n<p>=IF(Priority=&#8221;Low&#8221;,&#8221;&lt;DIV&gt;&lt;img src=https:\/\/&lt;your url&gt;\/sites\/SiteName\/SiteAssets\/icon-yellow.png title= Priority.is.LOW&gt;&lt;\/DIV&gt;&#8221;,IF(Priority=&#8221;Medium&#8221;,&#8221;&lt;DIV&gt;&lt;img src= https:\/\/&lt;your url&gt;\/sites\/SiteName\/SiteAssets\/icon-orange.png title=Priority.is.MEDIUM&gt;&lt;\/DIV&gt;&#8221;,IF(Priority=&#8221;High&#8221;,&#8221;&lt;DIV&gt;&lt;img src= https:\/\/&lt;your url&gt;\/sites\/SiteName\/SiteAssets\/icon-red.png title=Priority.is.HIGH&gt;&lt;\/DIV&gt;&#8221;)))<\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/create-indicator.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-523\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/create-indicator.png\" alt=\"create-indicator\" width=\"559\" height=\"742\" \/><\/a><\/p>\n<h3>Step 8 \u2013 Add new item to the list<\/h3>\n<p>Now we need to create an item in the list.<\/p>\n<p><b>Instructions:<\/b><br \/>\nClick on the new item link<br \/>\nTitle: <b>Work Item 01<\/b><br \/>\nPriority: <b>Low<\/b><br \/>\nThen click <b>Save<\/b>.<\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-item.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-524\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-item.png\" alt=\"add-item\" width=\"624\" height=\"280\" \/><\/a><\/p>\n<p>If all went well you should now see item 1 in the list and it will show the code for the low image in the indicator column.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/item-view-code1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-536\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/item-view-code1.png\" alt=\"item-view-code\" width=\"639\" height=\"140\" \/><\/a><\/p>\n<h3>Step 9 \u2013 Add the Text to HTML script and move it under the list<\/h3>\n<p>Now we need to add the Text to HTML script to tell SharePoint to render the image instead of the code. We\u2019ll do this by first getting the URL (address) to the script and then adding it into a new Content Editor on the page.<\/p>\n<p><b>Instructions:<\/b><br \/>\nGo into the Site Assets library, right hand mouse click on the script and select \u201c<b>Copy shortcut<\/b>\u201d.<\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/copy-shortcut.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-526\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/copy-shortcut.png\" alt=\"copy-shortcut\" width=\"506\" height=\"636\" \/><\/a><\/p>\n<p>Next click on the Visual Work list and then on the settings \u201cCog\u201d and then <b>Edit Page<\/b><\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/edit-page.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-527\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/edit-page.png\" alt=\"edit-page\" width=\"173\" height=\"351\" \/><\/a><\/p>\n<p>Then click on the ribbon and <b>select Insert <\/b>and then <b>Web Part<\/b><\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-web-part.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-528\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-web-part.png\" alt=\"add-web-part\" width=\"485\" height=\"498\" \/><\/a><\/p>\n<p>Then go to the Media and Content section and select the Content Editor option and click <b>Add<\/b>.<\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-content-editor.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-529\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-content-editor-300x79.png\" alt=\"add-content-editor\" width=\"300\" height=\"79\" \/><\/a><br \/>\nThe web part should now be added to the page just above the list. Next click on the upside down triangle and then click on the \u201c<b>Edit Web Part<\/b>\u201d link.<\/p>\n<p> <a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/edit-web-part.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-530\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/edit-web-part-181x300.png\" alt=\"edit-web-part\" width=\"181\" height=\"300\" \/><\/a><\/p>\n<p>After you click on the link the window should reload and show the editor for the Content Editor. In the content link section <b>paste the shortcut <\/b>that you copied from the Site Assets library and then click OK.<\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-link-to-content-editor.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-531\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/add-link-to-content-editor-294x300.png\" alt=\"add-link-to-content-editor\" width=\"294\" height=\"300\" \/><\/a><\/p>\n<p>Finally, in order to make the image render you will need to <b>drag the Content Editor underneath <\/b>the Visual Work list.<\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/move-content-editor-below1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-538\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/move-content-editor-below1.png\" alt=\"move-content-editor-below\" width=\"722\" height=\"407\" \/><\/a><\/p>\n<p>Next you need to click on \u201c<b>Stop Editing<\/b>\u201d<\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/stop-editing.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-533\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/stop-editing.png\" alt=\"stop-editing\" width=\"282\" height=\"256\" \/><\/a><\/p>\n<p>Now you should have the image rendering properly as below.<\/p>\n<p><a href=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/image-rendered.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-534\" src=\"https:\/\/themercers.ca\/OrderOutOfChaos\/images\/image-rendered-300x172.png\" alt=\"image-rendered\" width=\"300\" height=\"172\" \/><\/a><\/p>\n<p><b>NOTE:<\/b> Anywhere on your site that you want to show the image(s) you will need to add the content editor with the shortcut link and move it under the list or web part.<\/p>\n<div id=\"themify_builder_content-506\" data-postid=\"506\" class=\"themify_builder_content themify_builder_content-506 themify_builder\">\n    <\/div>\n<!-- \/themify_builder_content -->\n","protected":false},"excerpt":{"rendered":"<p>Creating Custom Key Performance Indicators with Calculated Columns Consider the following scenario A team wants to be able to prioritize their work so they can visually see what are the most important items to focus on. They will use low, medium and high priorities, represented by yellow, orange and red images. Things You Need Custom [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-506","post","type-post","status-publish","format-standard","hentry","category-sharepoint-2013","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/themercers.ca\/OrderOutOfChaos\/wp-json\/wp\/v2\/posts\/506","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themercers.ca\/OrderOutOfChaos\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themercers.ca\/OrderOutOfChaos\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themercers.ca\/OrderOutOfChaos\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/themercers.ca\/OrderOutOfChaos\/wp-json\/wp\/v2\/comments?post=506"}],"version-history":[{"count":3,"href":"https:\/\/themercers.ca\/OrderOutOfChaos\/wp-json\/wp\/v2\/posts\/506\/revisions"}],"predecessor-version":[{"id":512,"href":"https:\/\/themercers.ca\/OrderOutOfChaos\/wp-json\/wp\/v2\/posts\/506\/revisions\/512"}],"wp:attachment":[{"href":"https:\/\/themercers.ca\/OrderOutOfChaos\/wp-json\/wp\/v2\/media?parent=506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themercers.ca\/OrderOutOfChaos\/wp-json\/wp\/v2\/categories?post=506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themercers.ca\/OrderOutOfChaos\/wp-json\/wp\/v2\/tags?post=506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}