Nested IF statement

Hi,

I am having a problem with the nested IF statement when trying to use more than 3 arguments. Below is my statement. I am trying to display a previously entered name of a market (string) based on the selection for var5.

if(${var5}='1',concat('Name of previous market is ',${M1NAME}),if(${M5PMM}='2', concat('Name of previous market is ',${M2NAME}),if(${var5}='3', concat('Name of previous market is ',${M3NAME}),concat('Name of previous market is ',${M4NAME}))))

I am getting this error message: The problem was located in calculate expression for ${gr18}.1/var5 XPath evaluation: cannot handle function 'IF' Caused by: org.javarosa.xpath.XPathUnhandledException: The problem was located in calculate expression for ${gr18}.1/var5 XPath evaluation: cannot handle function 'IF' ... 10 more Result: Invalid

Thanks!

Hi @sacharya

your if statement looks ok and I was able to build a test form using it. the only thing I changed is replacing

to ${var5}='2' since in all other cases ${var5} was used. Maybe that was your mistake?

Here is the sample form I mentioned:
ifElseTest.xlsx (6.7 KB)

Hi Grzegorz,

I fixed that variable name and now I am getting another error message: ODK Validate Errors: >> Something broke the parser. See above for a hint. Dependency cycles amongst the xpath expressions in relevant/calculate Result: Invalid. This is the only change I have made in the form so there must be something wrong with the statement? Thank you.

Could you attach your form? As you can see my example with exactly the same statement works well.

1 Like

I tried again and it worked. There was a problem in the name column. Thanks so much for your help!

1 Like

Good to know, don't hesitate to ask in case of any problems.

1 Like