Select to view content in your preferred language

Peculiar behaviour when summing up questions

05-21-2024 10:13 PM
New Contributor II


I stumbled across some peculiar behaviour when trying to sum some yes/no questions. The 7 yes/no questions use a select_one yes_no with 1=Yes and 0=No.

A total questions has a calculation that sums the results as 



If I start ticking Yes from the top (question 1) to the bottom (question 7) the summation works as expected. If I start at the bottom (question 7) and go to the top (question 1), the total interprets the answer as strings and start concatenating the, so ,'1', '11', '111','1111','11111', '111111' until I tick the top question. Then the total changes to 7.

If I add another Total that converts the answers to integers before summing, I get a different behaviour. The total only gets calculated after all questions have been answered.

Attached are 2 videos showing the summations plus the XLSForm.

If you want to be sure that the calculations work, no matter what order they are ticked off, the following calculations should always work:





It's not a big thing, but something to keep in mind.

0 Kudos
1 Reply
MVP Regular Contributor

Your issue is that the questions aren't set to integer. When you see that behaviour it is classic "numbers being stored as text". Just set their bind type to "int" and the issue should go away.


EDIT: Just in case is wasn't clear, you will need to do this for everything involved in that calculation.