Help with calculation error message --trying to use calculate function to create a score

1. What is the issue? Please be detailed.
getting the following error when converting xlsform to ODK Xform

Error: ODK Validate Errors:

Something broke the parser. See above for a hint.
Error evaluating field 'heart_rate_score' (${heart_rate_score}[1]): The problem was located in Calculate expression for ${heart_rate_score}
XPath evaluation: cannot handle function 'if' requires 3 arguments. Only 7 provided.
Caused by: org.javarosa.xpath.XPathUnhandledException: The problem was located in Calculate expression for ${heart_rate_score}
XPath evaluation: cannot handle function 'if' requires 3 arguments. Only 7 provided.
... 10 more

The following files failed validation:
${SATS} ODK XLSForm .xml

2. What steps can we take to reproduce this issue?
try to manually convert XLS form

3. What have you tried to fix the issue?
carefully reviewed the formula

4. Upload any forms or screenshots you can share publicly below.
SATS ODK XLSForm .xlsx (22.3 KB)

Your parenthesis are not matched properly. With 3 if statements nested, it should look like this:
if(expression, then, if(expression, then, if(expression, then, else)))

Your relevant expressions for lines 40-43 are invalid. For example, if(${tews} >=7) is invalid. The format for an if statement is:
if(1, 2, 3)
where...
1 = statement to evaluate,
2 = value if statement is true, and
3 = value if statement is not true
So you would need to use something like:
if(${tews} >=7, true, false)
But that is redundant. You don't need to use an "if" statement, it just needs to evaluate to true or false so you can use only:
${tews} >=7

See the highlighted cells on this edited file:
SATS ODK XLSForm_edited.xlsx (22.4 KB)
It no longer reports an error when checked with https://getodk.org/xlsform/

More info in the docs:

2 Likes

Thanks so much! It worked

1 Like