Calculating NaN with Survey123 Connect

1546
3
04-09-2020 11:35 AM
KeithKatashuk
New Contributor II

Hey all,

I am trying to do a survey in which there is a scoring system set up. At the end, I want to add up all of the results into a grand total of points.

Each question I have follows the same point system based on if you answered Yes, No, or N/A.

"Yes" = 4 points.

"No" = 0 points

"N/A" = NaN

When I add up all of the survey answers to a final "Grand Total" field, it gives me a blank answer if any of them are "N/A" (NaN). 

The calculation I have set up is this:

int(${field1}) + int(${field2}) ....etc.

All of my calculations work just fine when they select either "Yes" or "No"....but as soon as even one of the options is set to "NA", the result is totally blanked out (due to the use of the "NaN"). Is there any work around for this?

0 Kudos
3 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Keith,

In your survey, how does "NaN" differ from 0?  If your total calculation is additive, then you would be fine with a value of 0 instead.  Technically, "NaN" would not be appropriate as any mathematical operation involving "NaN" results in "NaN".

0 Kudos
KeithKatashuk
New Contributor II

James,

I tried to set bot No and NA to 0 but when I did that, it would select both of them at once automatically if I chose either one (since they were both the same value). Even with the select_one option, it would pick them both no matter what unless I chose the Yes option.

We still want to make sure that we capture when someone pushes the NA button so we can take that into account when we average the scoring later. If there's an NA, we will simply omit the question so that way they don't receive 0 points for something they didn't have the option to do.

Here is the way that I fixed this issue. I used a max(int(${question1}), 0) + max(int$(${question2}),0) ....etc calculation to get my total points. Since the only thing of value was a "Yes" answer in my survey, it only looked for that and turned everything else into a 0 in my total calculation of points at the end.

The issue now is that after I published it, the survey works perfectly fine on my mobile device. However, when I try to take the survey in the web browser format, it's still showing blank data in the calculation if a NA option is selected. That may be a bug from what I'm hearing, waiting for the team to get back to me on that one.

0 Kudos
informaticacoopetarrazu
New Contributor II

Hola James

 

Para el caso de sacar promedio (media), el 0 me condiciona la respuesta. Por lo cual necesito que en el caso de no haber respuesta en la pregunta, sea un valor nulo 

Por ejemplo:

Saludos