I have a list with items that contains several columns like:

  • Year
  • Month
  • HourCategory1
  • HourCategory2
  • HourCategory3

Now I want to create a table that shows only totals of the hour categories:

HourCategory1 : Sum of all items
HourCategory2 : Sum of all items
HourCategory3 : Sum of all items
Total hours : Sum of all HourCategory1 + HourCategory2 + HourCategory3

How can I achieve this with out-of-the box functionality using existing WebParts/ Views or Javascript, JSLink XSL etc.


Solved it with XSL using a XsltListViewWebPart.

Created totalColumn template

  <xsl:template name="totalColumn">
    <xsl:param name="node"/>
    <xsl:param name="fieldName"/>
    <xsl:param name="sum" select="0"/>
      <xsl:when test="$node">
        <xsl:call-template name="totalColumn">
          <xsl:with-param name="node" select="$node/following-sibling::Row"/>
          <xsl:with-param name="fieldName" select="$fieldName"/>
          <xsl:with-param name="sum" select="$sum + translate($node/@*[name() = $fieldName], '.', '')"/>
        <xsl:value-of select="$sum"/>

Created three variables like

Then use it like this

<xsl:value-of select="$HourCategory1"/>
<xsl:value-of select="$HourCategory2"/>
<xsl:value-of select="$HourCategory3"/>
<xsl:value-of select="$HourCategory1+ $HourCategory2+ $HourCategory3"/>

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.