Calculate with if-else reset value when save

Hello, I have the followinf condition
if(/data/encuesta/datos_informante_clave/p3.01 = 1, if(/data/encuesta/datos_informante_clave/p3.02= 1, '1', '2'), '')
This is on the calculate valueof a quiestion and is required
But when try to save the form clean the value to null ('') and returns to the question asking for a value.

I'm with the lates ODK version

I think the solution is to store the current value but not sure how to get it

regards

1 Like

I'd love to help, but your post does not contain enough information for me to answer your question.

Can you attach a sample form that has this behavior? And can you please also specify the exact version number of ODK Collect?

Finally, when you get a chance, please introduce yourself here. I'd also encourage you to add a real picture as your avatar because it helps build community!

1 Like

Thanks Yaw,
Gladly I'll do, so I'm attaching a simple smaple xml file with the current problem .
ODK Version 1.10.2
Workflow sample:
*All fields are required.

  • As for the survey we ask your sex (M/F)
  • then if you're the owner of the house (Y/N)
  • if you are, we don't need to ask the sex again so we calcultae the value and copy from the first question (M/F)

CASE 1 in this stage all is ok
M, Y, M, Save
F, Y, F, Save

CASE 2 Here is the problem
M, N, M, Save,
M, N, F, Save,
F, N, F, Save,
F, N, M, Save,
On the third question you have to choose the sex of the owner, but when save/finalize the form it returns to the third question with a blank value and you enter in a loop.

calculate = if(/data/owner = 1, if(/data/sex = 1, '1', '2'), '')

the blank value comes from the first else (we don't want to assign a defalt value in order to avoid errors from the users), so the problem is tha when you finalize the form it do the calculate field again instead of saveing the current value selected.

TestSave.xml (2.8 KB)

Thanks for all your help

1 Like

Can you please attach the ODK Build file or export to XLS?

1 Like

Sure, TestSave.zip (575 Bytes)
here is the build file.

1 Like

This form does help explain the situation, so thanks for sharing it! The challenge here is that calculations are re-evaluated when you finalize, so your form as designed won't work.

I'd recommend that you make sex and owner required questions. Then make owner_sex relevant if owner is no. Then in your analysis, you'll know that if owner is yes, you know the owner_sex.

1 Like