Survey123 Calculation referencing a null decimal question

2181
6
10-15-2018 12:56 PM
KatherinePadilla
Occasional Contributor

Hello,

I am trying to write a calculation and I can't quite get it to work.

I have attached a couple screen shots to help explain what is going on.

The calculations I have written do not create any errors yet how the survey is filled in or rather not filled in, the answers to other questions appear when they should be null.  There are no defaults populated other than for Water Temp Device.

if(selected(${WTEMP_NUM},'NaN'),'',string('None'))

0 Kudos
6 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Katherine,

Is there a choice value of 'NaN' in the WTEMP_NUM choice list, or are you attempting to determine if the question is empty?  For a single or multiple-choice question, you can use count-selected(${WTEMP_NUM}) = 0 for an empty check.  For all questions, string-length(${WTEMP_NUM}) = 0 will work as a no value check.

KatherinePadilla
Occasional Contributor

So the referenced field WTEMP_NUM is a fill in decimal type.  The calculation I would like to make is this:  if WTEMP_NUM is null (not filled in), then the WTEMP_QUALIFIER shall be null, otherwise it shall be None.  I am also trying to make some relevancy statements referencing this filed as well that are not behaving as desired.  I am not sure if these types of statements work with this type of field (fill in decimal).  Perhaps there is a different way to reference these types of fields that will get the desired outcome?

0 Kudos
KatherinePadilla
Occasional Contributor

I did try to use an intermediate step that used the string-length function to calculate the 0 or 1 then referenced that field in the equation and it still did not workout as expected.

0 Kudos
StrathconaBTS
New Contributor III

Thanks for posting this James. I am successfully using count-selected for an empty check, however I did find a bug. If the name of the selected option is zero it does not return the appropriate count it returns zero. EG assume ${select_one_question}, choice name: 0, label: 'test', calling function count-selected(${select_one_question}) returns 0 instead of the expected 1.

0 Kudos
IngridAldridge1
New Contributor III

Hi Katherine,

The selected() calculation only works on the select_one or select_multiple question types.  For a decimal it is better to look at the length of the response.  For example: if(string-length(${WTEMP_NUM})>0,'','None').  This will look at the length of the response for your field ${WTEMP_NUM} and if it is greater than 0 i.e. filled in with anything it will give you a blank response '' but if it is not filled it will return the work None. A variation of this should also work in your relevancy statements as well. 

KatherinePadilla
Occasional Contributor

This works out well.  Thank you!!

0 Kudos