Select to view content in your preferred language

Survey calculations stopped working.

908
5
03-17-2020 08:08 AM
ClaibornPhillips1
Emerging Contributor

How do I calculate the totals for select multiple questions? I am sure that is what I have to work around given the ones without it calculate correctly. I am using the latest version of Survey123, so that has been ruled out as an issue. I have tried if then statements, coalesce, string-length, etc. and none of them seem to be working.

Thanks,

Tags (1)
0 Kudos
5 Replies
DougBrowning
MVP Esteemed Contributor

What exactly is not working?  Maybe a line number?  Screen shot?  You have 175 lines so it is hard to find it.  My guess is that you need to bind your integer and total questions to int in the bind::type column.

0 Kudos
ClaibornPhillips1
Emerging Contributor

To simplify, for the Anopheles group, starting at line 59, the user starts by choosing the species in that genus that has been trapped. In lines 61-68, the user can input the number of female and/or male mosquitoes caught of a particular species in that genus. The numbers entered are supposed to automatically add up as total females caught(line70), total males caught(line 71) and overall total(line 72). I had this working before, but for some reason it stopped working where the total section doesn’t show any value, it is just blank. I’m pretty sure it has to do with select_multiple since those are the only groups that do not perform the calculation like I would like it to. Is there a way to make this work with the type staying as select_multiple?

So the totals are supposed to add up, but obviously nothing is happening.

0 Kudos
DougBrowning
MVP Esteemed Contributor

Ok I see it now.  Your sum fields are trying to sum fields that are hidden due to the relevant.  When a field is hidden it gets the value '' - even if it is an integer.  It does not get the default value.  This '' is breaking your + sum.

So if I select just atropos then the other 3 values in this calc are '' and it breaks.

${An_atro_F} + ${An_cru_F} + ${An_pun_F} + ${An_qua_F}

How I do it is have a second field after each number that has and if.

if(${An_atro_F}='',0,${An_atro_F})

That way the calc just uses the 0 and you get an answer.

But There is now a new function called coalesce() also.  You can use it to only use the value if it is not ''.

Shortened example

coalesce(${An_atro_F},0) + coalesce(${An_cru_F},0) ...etc

I was doing the first way mainly because I had to also count for a avg but this coalesce seems easier to write out.

See Formulas—Survey123 for ArcGIS | Documentation 

Hope that helps.

0 Kudos
ClaibornPhillips1
Emerging Contributor

I added the coalesce to the totals lines, but what can I do to keep a value of zero for each line?

On the Survey123 website, only the data with the coalesce or a number entered has a value.

0 Kudos
DougBrowning
MVP Esteemed Contributor

Yep.  If a field is hidden due to a relevant it is always ''.  You cannot make it 0.

0 Kudos