-1

Is there any way to sum all values in one calculated column without losing decimal data?

We're using an XPath expression and it loses all decimal information. Where @myField is one calculated column

<xsl:value-of select="@myfield" />

And at the end the end of the group structure

<xsl:value-of select="sum($nodeset/@myfield)" />

I assume the problem is because it's a calculated column as if we use a numeric column it works fine.

Thanks

Edit:

There's three level of grouping (username, year, month) The formula is inside the last level.

  • Where exactly are you using that formula? Please provide more detail. – teylyn Jun 17 '13 at 9:12
  • I've added a little bit of more info, if you need anything else please be a little bit more specific as I'm not the one developing this feature. Thank you – GLlompart Jun 17 '13 at 9:59
  • It is still not clear where you are using this function. You have tagged with three tags, but there are very many different places where such a function could be applied. Please provide more details. Are you using an XSLT list view? Or a DVWP? Or custom code? What is the data source? What is the query? What are the field data types? What is the formula for the calculated column? How is it stored? – teylyn Jun 17 '13 at 10:07
0

Is the calculated column formatted as a number? You could try casting the values within the XPath:

<xsl:value-of select="number(@myfield)" />
0

The problem was happening because of the format of the numbers, first I tried unsuccessfully to change the format numbers are displayed. As It didn't work I tried to format the data passed to the sum function.

After a while I realized that there was another problem because I wasn't allowed to use functions inside the expression in the select attribute.

I was able to iterate through the values inside $nodeset and print foreach one this

<xsl:value-of select="number(translate(@myfield,',','.'))" />

with no error, but when trying to use the function it wouldn't work.

<xsl:value-of select="sum($nodeset/number(translate(@myfield,',','.')))" />

I used the first way showed in the answer for this question and worked like a charm.

https://stackoverflow.com/questions/647991/summing-numbers-with-comma-as-decimal-separator-in-xslt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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