Select to view content in your preferred language

# Sum() over calculate'ed values assumes they are Strings and concatenates

1631
7
05-24-2021 12:23 PM
New Contributor III

In this simple survey:

 type name label calculation begin repeat group1 Group 1 decimal repeated_decimal Repeated Decimal Number calculate calculated_decimal number(\${repeated_decimal}) end repeat decimal sum_of_decimal Sum of Decimal round(sum(\${calculated_decimal}),2)

the sum_of_decimal value ends up being the concatenation of the repeated_decimals, not the mathematical sum. It works OK if we sum() over repeated_decimal, but sum() assumes they are strings if over calculated_decimal

I tried adding number() in various places in the calculations, to no avail.

1 Solution

Accepted Solutions
MVP Esteemed Contributor

Ok you kinda lost me so I am attaching a sheet that shows you how.  You just need to set the bind type column to decimal.  Everything is a string while in 123 really until it uploads.  I know this sounds weird.  So you need to tell 123 to treat it as a decimal while in the form.  That is why it is doing a concat.

Edit :  Use a note to get around the refresh thing.  Then if you want the final value to store as a decimal use the bind esri field.

See attached.

7 Replies
MVP Esteemed Contributor

Yep this is posted a lot.  In the bind type column set as decimal.  You do it in the main field no need for the calculate field.

New Contributor III

We need to use the "calculate" field, because of a problem with the survey app and refresh buttons.

So, is there any way to get sum() to add the numbers in a "calculate" field?

MVP Esteemed Contributor

Ok you kinda lost me so I am attaching a sheet that shows you how.  You just need to set the bind type column to decimal.  Everything is a string while in 123 really until it uploads.  I know this sounds weird.  So you need to tell 123 to treat it as a decimal while in the form.  That is why it is doing a concat.

Edit :  Use a note to get around the refresh thing.  Then if you want the final value to store as a decimal use the bind esri field.

See attached.

New Contributor III

Yes, that works! If I set bind::type of the calculate_decimal to decimal, as per below, then the sum() adds up the numbers. Thanks!

Occasional Contributor

I don't have the bind::type column for some reason. Why would that be? Is it because I've had this survey for a while. It seems to be concatenating now, but it wasn't previously.

MVP Esteemed Contributor

Yes you would need to add any new columns manually if they are new.  This is fine for quick fixes.

Eventually you will prob want all the new drop down values etc.  See this post for 2 ways to do it.

https://community.esri.com/t5/arcgis-survey123-questions/how-do-i-update-xls-form-to-conicide-with-u...

Note the method I posted in there is now harder since the order of the columns is now a lot different.  Still not too difficult though.

Hope that helps

Occasional Contributor

Thanks Doug, it helped tremendously. I had no idea that I could add the columns manually, but I did, and now the additions are working well. Thanks!