IF sentence for XLSForm

Hi again!

I’m working on a form that requires calculating a value based on 5 inputs. The problem is that the 5 inputs are not mandatory questions (respondants can input just 3/5 or 4/5 questions, and the form must calculate either way)

Originally I had a repeat group to capture the five inputs (they were the same question… For example Length1, Length2, etc), but decided to drop the repeat (it was becoming really complex for my Kobo experience level).

So I separated the group into five differente questions. I’m trying to use some sort of IF(logicValue;trueStatement;falseStatement) logic to check if the value on the input is not null, for it to be considered on the calculation.

On another thread I found an IF expression but after using it, I got this error when validating the XLSForm:

Error: ODK Validate Errors:

XForm is invalid. See above for the errors.
: Invalid calculate for the bind attached to “${verif_eval_obj1}” : Couldn’t understand the expression starting at this point: …obj1 != null,͎${eval_obj1],5) in expression if( ${eval_obj1} != null, ${eval_obj1],5)

The following files failed validation:
${UploadKobo_EvalDesempe}ñov4.xml

Result: Invalid

Not sure if should try with semicolon instead of comma as separators.

Is there any way to do an IF statement on a XLSForm? Or any other ways to address this issue?

EDIT:
Had a syntax error. Already corrected. Sorry! I’ll get back after some tests on fucntionality.

EDIT2:
So… The sentence is if(${eval_obj1} != null, ${eval_obj1},5).

It should check if there is a value selected on the eval_obj1 (select_one type question). If this is true, it should show the value on the variable otherwise it should show 5 on the next text type question.

But no matter what I choose on the select_one it always displays 5. Seems like the calculate type question is only evaluating the IF statement when the form loads, but not when I select a value on the select_one.

Any ideas here?

UploadKobo_EvalDesempeñov4.xls (95.5 KB)

Lines 22 and 23

There is no “null” in standard syntax. For an empty select_one, you would use “” (or ‘’), i.e. empty string. You might also use count-selected(…) = 0. See ODK XForms Specification.

1 Like