If in choice_filter xlsform

I've worked with XLSForms in Survey123 (ESRI).

I am trying to use if() structure in choice_filter field, but I am having some problems.

Is it possible to use if() structure in choice_filter or only in calculation field?

thanks a lot!!!

Can you please share your part of the XLS and explain details what out put you want using if function in the choice_filter?

company.xlsx (55.0 KB)

Arif,

My real XLSForm is so big and could be some confusing for you, then I created a smaller XLSForm but with the same idea that the original.

In the attached file I have 5 companies (babel, amazon, pilsen, kansas and tylor), but just Babel and Amazon have regional offices in 5 diferente cities (Martold, Phillie, Curitiba, Kansas and Natal).

The problem is coming now...In each Regional Offices, Babel has 3 operational routes and Amazon only 2. The other companies have only one route in their headquarter.

For this, I was trying using the IF () structure in choice_filter to populate the choice list. (Babel 1,2 or 3, Amazom 1 or 2,....) In the attached file I didn´t the IF() structure, but in my concepcion it would be necessary a chain of the IF inside the other.

If you need more information, ask me.

Thanks for your help.

Check the XLS form. If it work then let us know company.xlsx (61.3 KB)

I cant answer your original question per se, but if you want to nest an if() statement inside another if() statement, ie to effectively make an IF (foo='A') THEN do-this ELSE IF (bar='B') THEN do-that ELSE do-other, it looks like this in XPath:

if(${foo}='A', ${result-for-fooA-do-this}, if(${bar}='B', ${result-for-barB-do-that}, ${result-for-do-other}))

Basically, what you have currently - if(selected(${companies},'babel'),companies=${companies},'error') - is semantically wrong and will probably give unpredictable results.

1 Like

Arif,

Thanks a lot!!! But my example is a little simplified.

The correct example is:

Babel - Martold has 3 routes (1, 2 or 3)
Babel - Phillie has 4 routes (1, 2, 3 or 4)
Babel - Curitiba has 2 routes (1 or 2)
Babel - Kansas has 5 routes (1, 2, 3, 4 or 5)
Babel - Tylor has 1 route (1)

Amazon - Martold has 2 routes (1, or 2)
Amazon - Phillie has 4 routes (1, 2, 3 or 4)
Amazon - Curitiba has 1 route (1)
Amazon - Kansas has 4 routes (1, 2, 3, or 4)
Amazon - Tylor has 2 routes (1 or 2)

And other companies have only one route in their headquarter.

Now, the example is correct.

Thansks again for your help.

@aleprado You can try this way:company.xlsx (62.6 KB)