1,804 articles and 14,523 comments as of Friday, January 14th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint (Joel Oleson) content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Thursday, December 18, 2008

KPIs for the Masses: A Dashboard based upon a date-time field

In my the first two articles of this series, Visual Indicators for the Masses and Embed KPIs as a List View, I discussed ways to create simple KPIs in WSS. This article will show how to make calculations on top of date-time fields.

Calculated fields do not update themselves until the item itself is updated. Dessie Lunsford proposed a workaround, so we cannot use calculated columns nor built in KPI web parts. The approach below does not have that limitation.

Dashboard based on date-time fields (relative to Today)

Let’s say we have a requirement that states: Show a list of active issues with a status indicator that alerts you if a task is overdue.

Create the following:

  1. An Issues list based on the default Issues list template
  2. A list view for issues list

The date must be transformed to the date numeric format – Julian Day in order to calculate the difference between two dates . It is the interval of time in days and fractions of a day, since 4713 BC January 1, Greenwich noon. The original function is delivered with WSS Time Track Template.

Use the following XLST code to calculate the Due Date. It calculates the difference (as an integer) between two parameters: StartDate and TodayDate. Add the code to your list view stylesheet.

  <xsl:template name="DateDiff">
    <xsl:param name="StartDate"></xsl:param>
    <xsl:param name="TodayDate"></xsl:param>

    <xsl:variable name="JulianToday">
      <xsl:call-template name="calculate-julian-day">
        <xsl:with-param name="Year" select="substring(ddwrt:FormatDateTime(string($TodayDate), 1033, 'yyyyMMdd'),0,5)"/>

        <xsl:with-param name="Month" select="substring(ddwrt:FormatDateTime(string($TodayDate), 1033, 'yyyyMMdd'),5,2)"/>

        <xsl:with-param name="Day" select="substring(ddwrt:FormatDateTime(string($TodayDate), 1033, 'yyyyMMdd'),7,2)"/>
    </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="JulianStartDate">
      <xsl:call-template name="calculate-julian-day">
        <xsl:with-param name="Year" select="substring(ddwrt:FormatDateTime(string($StartDate), 1033, 'yyyyMMdd'),0,5)"/>

        <xsl:with-param name="Month" select="substring(ddwrt:FormatDateTime(string($StartDate), 1033, 'yyyyMMdd'),5,2)"/>

        <xsl:with-param name="Day" select="substring(ddwrt:FormatDateTime(string($StartDate), 1033, 'yyyyMMdd'),7,2)"/>
    </xsl:call-template>
    </xsl:variable>

    <xsl:value-of select="$JulianStartDate - $JulianToday"></xsl:value-of>
  </xsl:template>

  <xsl:template name="calculate-julian-day">
    <xsl:param name="Year"/>
    <xsl:param name="Month"/>
    <xsl:param name="Day"/>    

    <xsl:variable name="JulianDay" select="floor((14 - $Month) div 12)"/>
    <xsl:variable name="JulianYear" select="$Year + 4800 - $JulianDay"/>
    <xsl:variable name="JulianMonth" select="$Month + 12 * $JulianDay - 3"/>    

    <xsl:value-of select="$Day + floor((153 * $JulianMonth + 2) div 5) + $JulianYear * 365 + floor($JulianYear div 4) - floor($JulianYear div 100) + floor($JulianYear div 400) - 32045"/>
  </xsl:template>

In order to show the indicator add the following code to your output. It will show a red icon for overdue task, a yellow icon for a task that will be overdue next week, and a green icon for other tasks.

<td class="ms-vb">
    <xsl:variable name="DueDateDiff">
        <xsl:call-template name="DateDiff">
            <xsl:with-param name="StartDate" select="@DueDate"></xsl:with-param>
            <xsl:with-param name="TodayDate" select="ddwrt:TodayIso()"></xsl:with-param>
        </xsl:call-template>
    </xsl:variable>

    <img alt="Indicator" >
        <xsl:attribute name="src">
            <xsl:choose>
                <xsl:when test="$DueDateDiff &lt; 0">/_layouts/images/ewr218m.gif</xsl:when>
                <xsl:when test="$DueDateDiff &lt;= 7">/_layouts/images/ewr219m.gif</xsl:when>
                <xsl:otherwise>/_layouts/images/ewr217m.gif</xsl:otherwise>
            </xsl:choose>
        </xsl:attribute>
    </img>
</td>

The final output will look like this one.

Figure 03

Conclusion

WSS has limitations when it comes to creating KPIs, With these three articles, I have demonstrated a few ways to generate KPI type indicators within WSS. I hope it has given you some new ideas and you’ll let me know how your experiments turn out .

Toni FrankolaAuthor: Toni Frankola
SharePoint Use Cases
Toni started his Web adventure in late 90’s and has been working with various web technologies ever since.

Toni is leading project engagements and managing a team of consultants specializing in Microsoft technologies. His primary focus is on Microsoft Office SharePoint and Dynamics CRM. He works at Perpetuum Mobile, a Microsoft Gold Partner from Croatia.

 

Please Join the Discussion

7 Responses to “KPIs for the Masses: A Dashboard based upon a date-time field”
  1. Prakash says:

    I didn’t get where I need to put the second code that you have written

  2. Jerad says:

    It appears the XLST code is no longer available. Is there a location that I can download it?

  3. Anthony says:

    Toni this is a great article, really helped me setup some aging indicators on several lists. I am trying to use this same technique to do a count of list items that have aged past a certain point. For example

    The results are always either 0 or the total number of items and I’ve played around with the operator changing from ;gt= and ;lt=.
    Any idea?

    Thanks for your help,

    -Anthony

  4. Aravind says:

    Thanks a ton…Superb article!!!

Trackbacks

Check out what others are saying about this post...
  1. [...] KPIs for the Masses: A Dashboard based upon a date-time field In my the first two articles of this series, Visual Indicators for the Masses and Embed KPIs as a List View, I discussed ways to create simple KPIs in WSS. This article will show how to make calculations on top of date-time fields. Read more… [...]

  2. [...] The simplest solution is to use Julian Day Calculation. I already wrote about it in my previous article about KPIs. [...]




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!