Count/sum rows grouped by in XSLT Dataview WebPart
Scenario: Converted a list view to XSLT View using SharePoint Designer and grouped the list by 2 columns "Created By" (built in people and column group) and "WeekEnding" (date field).
Requirement: To display the count of each item that is grouped by "Week Ending" and "Created By" column. Also, sum of "% of Week" column with the same condition.
http://2.bp.blogspot.com/-5ANnO3RwS-k/UNxFQi3YOAI/AAAAAAAADLw/9faWlbLREPo/s640/group.JPG
Solution:
- Declare param** <xsl:param name="usernamegroup"/>** after the following lines <xsl:template name="dvt_1.groupheader0"> and <xsl:template name="dvt_1.groupheader1">
2. Search for the following line and add **xsl:with-param **after it
**<xsl:call-template name="dvt_1.groupheader1"> **
<xsl:with-param name="usernamegroup" select="substring-after(substring-before(substring-after(@Author, 'ID='), '<'), '>')"/>
Added it in two locations.
- Added the following line of code to display the count in header row(refer screenshot)
<xsl:value-of select="count(/dsQueryResponse/Rows/Row[(@WeekEnding=$fieldvalue) and (substring-after(substring-before(substring-after(@Author, 'ID='), '<'), '>')=$usernamegroup)]/@Week_Ending)">
- Added the following line of code to display the sum in the header row(refer screenshot)
<xsl:value-of select="format-number(string(sum(/dsQueryResponse/Rows/Row[(@WeekEnding=$fieldvalue) and (substring-after(substring-before(substring-after(@Author, 'ID='), '<'), '>')=$usernamegroup)]/@PercentageOfWeek)),'#,##0%;-#')" />