SP2010: I need to come up with a total (number) of a column for all entries in a list. For instance:

Given a list with entries which can be comprised of apples, oranges, and pears, and their corresponding counts, with the first column being the type, second column being the count. There can be multiple entries for each type. How do I total the count?

Column1 = type; Column2 = count

  • apple; 20
  • apple; 15
  • pear; 12
  • orange; 30
  • pear; 20
  • orange; 19

I can get the list item count using the following:

<xsl:variable name="count" select="count(dsQueryResponse/Rows/Row[normalize-space(@type) = 'apple']) />

If this is used, on the above list, it would make the variable count = 2 where the type equals apple. What would I need to use to sum up the column of an entire list? With the above, the apple total would be 35.

To round out what I'm doing, I'm using the variables to plug into jQuery/flot to display into a bar graph through an aspx page. I'm doing my coding using SPD2010. The data is being drawn from the list using a Data View WebPart. I cannot use/purchase/install any third party software (like Nevron Chart ) whether free or not. Visual Studio is not available to me. Please let me know if more information is needed.


I found I can do a sum of all of the line items by doing the following:

<xsl:value-of select="sum(dsQueryResponse/Rows/Row/@type)" />

But not sure how to segregate "apple" from "pear" using this.

2 Answers 2


Try using the sum function http://msdn.microsoft.com/en-us/library/ms256160.aspx

You can apply the same sort of filtering but sum on your column2.

<xsl:variable name="total" select="sum(dsQueryResponse/Rows/Row/@column2[normalize-space(@type) = 'apple']) />

Not tested but this should give you a total for all the apples.

To be more dynamic you would need to do a for-each loop through each @type.

  • Thanks. I will look at this when it get to work tomorrow. Commented Jul 25, 2013 at 22:54
  • I used this, but am not getting an output. I think it comes up with zero (0), as the plots on the graph show the bar but all bars show no dimension. I'll play with this to see if I can get it to work. Commented Jul 26, 2013 at 14:19

I haven't tested it, but I believe it should be, the count of all nonempty types:

<xsl:variable name="count" select="count(dsQueryResponse/Rows/Row/[normalize-space(@type) != '']) )" /> 

or just to get the count of the result set

<xsl:variable name="count" select="count(dsQueryResponse/Rows)" />

If you are going to use DVWPs to surface data for 3rd party charting libraries, which I'm doing more and more of these days, this is a very helpful article to have on hand if you haven't seen it already.

  • I don't believe this will work for what I'm doing ... I'm looking to get a total where a[1] + a[2] + ... a[n] = a[total]. I'm not seeing as how your answer gives me much of anything besides what I have now for getting a row count. I could be out in the weeds, though ... wouldn't be the first time ;-) Commented Jul 25, 2013 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.