Do you want to add totals to your List Rollup data view? Follow these simple steps...

When you create a list view in SharePoint, you have the option to group the data and also to add totals - these are nice features for those of you who want to see a count of the items in each group. When you create a list rollup data view using our List Rollup Web Part, you specify a list view to tell us what items you want to rollup (aggregate). However, today we don't use the grouping or totals that you might have configured on that view. We use the columns - we create the rollup data view with the same columns as the view specified. But you want your rollup grouped by default and you also want to display item counts in the group headers - how to do it? Follow these simple steps.

First, create your list rollup data view and refer to either or both of these KB articles to define grouping/sorting, hide the toolbar**, and collapse the groups by default.

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 referred to KB #10892 to group the items by the List Name column (fyi - the column name for that is bsc_ListName) and to turn off the Filter/Sort/Group toolbar that appears by default. I also added the text List Name to the header to replace the column name bsc_ListName that appears when I group by that column. The steps to replace bsc_ListName aren't included in the KB article, but it's easy to do, just:

  • 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 </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. As you can see in the screen shot below, I only made a change in the dvt_1.groupheader template.
  • 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>:

with this (I added the text shown in red)

<b><!--<xsl:value-of select="$fieldtitle" />--></b>List Name:

  • Copy all the text you have in Notepad back to your Windows clipboard and replace all the text you have in the Text Entry box of your data view web part. Click the Save button on the Text Entry box and it will close.
  • Then click the Apply button in the web part tool pane. You should see your changes applied to your data view (even though you are still in edit mode). My results are shown below.

OK - now we are ready 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, change the two tags after it, 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="fieldtitle" select="$dvt_groupdisplay" />-->
<!--<xsl:with-param name="fieldname" select="$dvt_groupdisplay" />-->

  • Next, we need to create a new variable in the dvt_1.groupheader template definition area. I called the 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="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):

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

  • That's it. You're done. My list rollup data view now looks like this:

 

Please note one thing to be wary of - the version of my List Rollup web Part is v4.0.46.0. If you are using an earlier version, the data view may have a slightly different configuration and the text strings may be a little bit different. It's best to upgrade to the latest version.

**If you'd rather not hide the toolbar, check out Add Totals to the Dynamic Groups that Appear in your List Rollup Data View, another article that describes how to put the totals on the dynamic group header.


Posted Jun 12 2009, 11:00 AM by Julie Auletta

Comments

Rob wrote re: Do you want to add totals to your List Rollup data view? Follow these simple steps...
on Wed, Jun 17 2009 9:54 AM

I found this article very helpful, thanks.  

One suggestion for other readers and maybe an option you can add to this article:  

If you decide to keep the sort/filter bar you will need to modify this procedure slightly -

Don't modify the line <b><xsl:value-of select="$fieldtitle" /></b>:  If you comment the line out, then when you change the group by selection the titles will not change.

Also, don't change <xsl:with-param name="fieldtitle" select="$dvt_groupdisplay" /> either, as this is needed as well.  

Julie Auletta wrote re: Do you want to add totals to your List Rollup data view? Follow these simple steps...
on Wed, Jun 17 2009 6:20 PM

Thanks for the suggestion Rob. I will work an addendum that explains the details of adding the count to the grouping selected in the toolbar - that's a great idea.

Julie Auletta wrote re: Do you want to add totals to your List Rollup data view? Follow these simple steps...
on Fri, Jun 19 2009 3:47 PM

Check out the new blog post  - it explains how to leave the toolbar displayed and show counts on the dynamic group headers. Thanks to Rob for suggesting this alternative!

Joyce Goad wrote re: Do you want to add totals to your List Rollup data view? Follow these simple steps...
on Mon, Jul 12 2010 11:18 AM

SharePoint also has a SUM total in its View options. Can the above steps be adapted (how?) to add a SUM for a number column in the List Rollup data view?

Julie Auletta wrote re: Do you want to add totals to your List Rollup data view? Follow these simple steps...
on Tue, Mar 8 2011 5:33 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 (with the pink text too) in the post above would become:

<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 (like I did), 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