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

629
7
Jump to solution
05-24-2021 12:23 PM
JoseVidal
New Contributor III

 

In this simple survey:

 

typenamelabelcalculation
begin repeatgroup1Group 1 
decimalrepeated_decimalRepeated Decimal Number
calculatecalculated_decimal number(${repeated_decimal})
end repeat   
decimalsum_of_decimalSum of Decimalround(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.

 

0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Notable 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.

View solution in original post

7 Replies
DougBrowning
MVP Notable 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.

0 Kudos
JoseVidal
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?

0 Kudos
DougBrowning
MVP Notable 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.

JoseVidal
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!

0 Kudos
ShannonPugh
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.

0 Kudos
DougBrowning
MVP Notable 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

ShannonPugh
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!

0 Kudos