Add Totals to the Dynamic Groups that Appear in your List Rollup Data View

If you've read my blog post Do you want to add totals to your List Rollup data view? Follow these simple steps... you might be thinking, that's nice but I don't want to have a default grouping, put hard-coded text in the group header, and I want to have the filter/sort/group toolbar displayed because it lets my end users group on the fly. This post is for you. It aims to explain how to add totals to your dynamic groups. If this is what you need to do, follow these simple steps.

For the purpose of this discussion, I rolled up a few Tasks lists, I included the List Name in the rollup, but not the Site Name (all my lists are on the same site). The default rollup is shown below.

Next, I modified the XSLT to add the counts. Here are the steps for that:

  • Modify the Data View Web Part
  • In the Web Part tool pane, click the XSL Editor... button
  • In the Text Entry box that appears, press Ctrl+A on your keyboard to select all the text, and then Ctrl+C to copy it to your Windows clipboard. Then paste it into Notepad. Notepad has a search feature, but unfortunately the Text Entry box doesn't. If you'd prefer to use another editor, feel free.
  • Once the text is in Notepad, search for <xsl:call-template name="dvt_1.groupheader">. It should be in there only once.
  • Once you find it, comment out two tags that are there and add three new tags, so this:

<xsl:call-template name="dvt_1.groupheader">
<xsl:with-param name="fieldtitle" select="$dvt_groupdisplay" />
<xsl:with-param name="fieldname" select="$dvt_groupdisplay" />

will become this (I added the text in red):

<xsl:call-template name="dvt_1.groupheader">
<xsl:with-param name="fieldtitle" select="$dvt_groupfield" />
<xsl:with-param name="fieldname" select="$dvt_groupfield" />
<xsl:with-param name="fieldnamedisplay" select="$dvt_groupdisplay" />
<!--
<xsl:with-param name="fieldtitle" select="$dvt_groupdisplay" />-->
<!--<xsl:with-param name="fieldname" select="$dvt_groupdisplay" />-->

  • Next, we need to create the variable for the field name display in the dvt_1.groupheader template definition area. This defines the variable for the display name for the column that we will show in the groupheader. Without this, we will see the internal field name in the group header, rather than the display name (display names look nicer). In Notepad, search for <xsl:template name="dvt_1.groupheader">. It should be in there only once.
  • Once you find it, you will add a tag. Change these lines:

<xsl:template name="dvt_1.groupheader">
<xsl:param name="fieldtitle" />
<xsl:param name="fieldname" />

to this (the text I added is in red):

<xsl:template name="dvt_1.groupheader">
<xsl:param name="fieldnamedisplay" />
<xsl:param name="fieldtitle" />
<xsl:param name="fieldname" />

  • Now we will use that new parameter we called fieldnamedisplay. In Notepad, search for </b>: This string is in there twice, once in the dvt_1.groupheader template definition, and the second time in the dvt_1.groupfooter template definition. We only want to change the one in the dvt_1.groupheader template definition.
  • When you find the string in the groupheader, look for the following text around it - you want to replace this:

<b><xsl:value-of select="$fieldtitle" /></b>: <xsl:choose>

with this (the text I added is in red):

<b><!--<xsl:value-of select="$fieldtitle" />--><xsl:value-of select="$fieldnamedisplay" /></b>: <xsl:choose>

  • Next, we need to create another variable for the count in the dvt_1.groupheader template definition area. I called this variable groupcount and added it after the first <td> tag in the template definition. This variable counts the occurrences of the Title column (see the @Title in pink below), so if your list rollup data view doesn't include that column, choose a column that is included in your data view. Now, the first part of my template definition looks like this (the text I added is in red - and pink):

<xsl:template name="dvt_1.groupheader">
<xsl:param name="fieldnamedisplay" />
<xsl:param name="fieldtitle" />

<xsl:param name="fieldname" />
<xsl:param name="fieldvalue" />
<xsl:param name="fieldtype" />
<xsl:param name="nodeset" />
<xsl:param name="groupid" />
<xsl:param name="displaystyle" />
<xsl:param name="imagesrc" />
<xsl:param name="alttext" />
<xsl:param name="altname" />
<xsl:param name="hidedetail" />
<tr id="group{$groupid}" style="display:{$displaystyle}">
<td class="ms-gb" style="background:#cccccc;" colspan="99">
<xsl:variable name="groupcount" select="count($nodeset[*[name()=$fieldname]=$fieldvalue or ($fieldtype!='isodatetime' and @*[name()=$fieldname]=$fieldvalue) or ($fieldtype='isodatetime' and ddwrt:GenDisplayName(string(@*[name()=$fieldname]))=$fieldvalue) or (not(*[name()=$fieldname] or @*[name()=$fieldname]) and $fieldvalue = ' ')]/@Title)"/>

  • Finally, we need to display the value of our new variable groupcount in the dvt_1.groupheader template definition area. In the template definition area, somewhere BENEATH where you added the variable entry explained above, add the display for the count. I added it at the end of the group header row, so the last part of my template definition looks like this (the text I added is in red - don't forget the space before the square bracket):

</xsl:choose> [count: <xsl:value-of select="$groupcount" />]
</td>
</tr>
<tr><td colspan="99"></td></tr>
</xsl:template>

  • That's it. You're done. Counts will now appear regardless of the column your end user chooses to group by. My list rollup data view now looks like this:

 


Posted Jun 19 2009, 03:26 PM by Julie Auletta

Comments

tpk193 wrote re: Add Totals to the Dynamic Groups that Appear in your List Rollup Data View
on Wed, Nov 25 2009 5:00 PM

I need to total the values from a column like 'Work' instead of a total count.  Can that be done?  If so, how?  Thanks.

Julie Auletta wrote re: Add Totals to the Dynamic Groups that Appear in your List Rollup Data View
on Wed, Nov 25 2009 5:35 PM

You should be able to sum any column that is a number. Instead of using a COUNT you will use a SUM. I summed a column called AMOUNT in one of my rollups and I formatted the number as currency. I also changed the variable name to groupsum instead of groupcount. The code in red in the post above becomes:

<xsl:variable name="groupsum" select="format-number(sum($nodeset[*[name()=$fieldname]=$fieldvalue or ($fieldtype!='isodatetime' and @*[name()=$fieldname]=$fieldvalue) or ($fieldtype='isodatetime' and ddwrt:GenDisplayName(string(@*[name()=$fieldname]))=$fieldvalue) or (not(*[name()=$fieldname] or @*[name()=$fieldname]) and $fieldvalue = ' ')]/@Amount), "$#,##0.;-$#,##0.")"/>

If you change the variable name, you will need to change it a few places. I hope this helps.

Add a Comment

Please sign into Bamboo Nation to leave a comment.

About Julie Auletta

As Solutions Director for Bamboo Solutions, Julie Auletta is responsible for all areas of services and consulting, including packaged software products and custom applications. She brings more than 20 years of consulting experience to her position, having led numerous successful consulting organizations. Prior to Bamboo Solutions, Julie managed a Project Management Group for Litton/PRC, where she was responsible for implementing commercial-based enterprise document management solutions for various government and commercial projects. Prior to heading the Project Management Group, Julie helped form the Product Quality and Test Group used to ensure quality deliverables for the software product development group. Julie also worked as a Facilities Engineer for Litton/PRC involved in several projects relating to facility and utility planning, Environmental Impact, and Feasibility Studies. Julie holds a M.S. in Urban Planning from the University of Virginia and a B.S. in Mechanical Engineering from Lehigh University.

Blogs

    The Bamboo Team Blog
  • Home

Bamboo Nation, Media Sponsor of:

SPTechCon

Subscribe by Email

Syndication

Bamboo Nation Almost Everywhere

Follow Bamboo Nation on:Bamboo Solutions on Facebook

Bamboo Solutions on Google+

Bamboo Solutions on LinkedIn

Bamboo Solutions on Twitter

Bamboo Solutions on YouTube

Bamboo Now in Alltop!

        Featured in Alltop

SharePoint Calendars

SharePoint Calendars

Bamboo Solutions Corporation, 2002-2012