Survey123 Addition Calculation Treating Numericals as Text Fields

5671
3
Jump to solution
12-15-2015 07:10 PM
SimonAllard1
New Contributor III

Hello all,

I am working on a field survey that looks at sampling algal cover in streams across the Bay of Plenty Region in New Zealand. I am trying to create an error check field that is used to ensure that users enter % cover for algae types that will sum to 100%.

First question is a select multiple where the user selects all algal types that they have at the site. Then the %cover of the relavant algal types is entered by the user. I was to ensure that these % cover of algal types sums to 100% and if it does not - a error message is displayed and the user corrects his cover values.

Here is my construct in excel

the calculation is:

(${percent_no_algae1_1}+${percent_film1_1}+${percent_mats1_1}+${percent_cyano1_1}+${percent_sludge1_1}+${percent_green_fa1_1}+${percent_brown_fa1_1})

This is what happens below: the algal cover percentages are treated as a text field and the number 50+50 = 5050 instead of 100. I also have a constraint on this value and it must equal 100 (.=100). I have tried integer and decimals fields, and even used the bindesri fields to set them to integer or decimal but with no success.

Has anyone had a similar issue occur to them in a calculation like this. Can I use a sum function instead of additions or is my addition syntax wrong?

Thanks in advance for you help.

Simon

1 Solution

Accepted Solutions
SimonAllard1
New Contributor III

Found a solution to this by enforcing the calculation variables as integers.

This was the thread which helped me solve this.

"When using mathematical operators, be aware that sometimes you may need to cast values into numbers. In the previous examples we assumed that previous_question and other_previous_question where integers or decimals... but what if the question types were strings? Then you cast them as follows:"

int(${previous_question}) + int(${other_previous_question}) <= 100

View solution in original post

3 Replies
SimonAllard1
New Contributor III

Found a solution to this by enforcing the calculation variables as integers.

This was the thread which helped me solve this.

"When using mathematical operators, be aware that sometimes you may need to cast values into numbers. In the previous examples we assumed that previous_question and other_previous_question where integers or decimals... but what if the question types were strings? Then you cast them as follows:"

int(${previous_question}) + int(${other_previous_question}) <= 100

DanPatterson_Retired
MVP Emeritus

Simon, mark your answer correct so that others may know that this type of issue has a resolution.

ThomasKrinke
New Contributor II

Thank you Simon.

0 Kudos