Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

This is akin to this question but I couldn't get the suggested sumAll function to work. I also have several different columns to sum and it just seems silly to have a separate template for each column I want to sum. I have a column where not all rows have a value. I want to sum the rows that do have values. I have tried the following:

<xsl:value-of select="sum($nodeset/@MyField[string-length(@MyField) &gt; 0])" />

This seems like it should work. However, I get 0 as the total. The very same data view shows individual rows below the total with values like 300, 160, etc., so 0 is obviously an incorrect total. I have tried wrapping @MyField in number(), but I end up getting NaN as the total then. All the examples I've seen online talk about translate() and dealing with British-style decimals, but I'm working with American-style decimals and I don't see any individual values with commas.

How can I sum this column?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I'm not positive that this will answer your entire question as I'm not certain about your use of decimals etc.

Try replacing the string-length(@MyField) with string-length(.) :

<xsl:value-of select="sum($nodeset/@MyField[string-length(.) &gt; 0])" />

I've tested this quickly and this returns a value where your expression returned 0, so it should go a long way to solving your problems.

share|improve this answer
    
That got it! I'd vote you up but I don't have the reputation for it. :( –  Sarah Vessels Nov 4 '10 at 14:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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