Select to view content in your preferred language

Survey123 connect XLS nested if statement problem

288
1
05-30-2024 08:21 AM
leighlager
Emerging Contributor

Would appreciate an assist on syntax issues.  Trying to use a nested if statement to get me the value I want.  

Region is a field that has a picklist (using selectone with the reference to the choice list).  Have it set as default so all the choices are displayed and the user hits the button for their choice.  The button is selected in the survey and the value behind that button is VHGMI.  The mac_index_score is automatically calculated in the survey.  

What I want:  if the button for VHGMI is selected and the mac_index_score is over 13 then I want the value 'gt13' returned.  if the VHGMI button is selected and the mac_index_score is under 13, then I want the value returned to be 'lt13'.  If none of those conditions is true, then I want 'none of the above returned'.  (this is just for illustration purposes)

What I have that isn't working (it is returning 'none of the above despite me clicking the right button and having a value over 13......)

if(selected${region} = VHGMI and ${mac_index_score} > 13, 'gt13', if(selected${region} = VHGMI and ${mac_index_score} <= 13, 'lt13', 'none of the above'))

This could be as simple as bad syntax....but I've tried lots of combos to no avail.  Maybe I need to use pulldata somewhere?  No idea.  If someone could point me in the right direction, I would greatly appreciate it.  

Thanks in advance.

0 Kudos
1 Reply
jcarlson
MVP Esteemed Contributor

You need parentheses on your selected functions, and you need to put your values in quotes.

EDIT: Selected needs to have the compared value as a second parameter. Oops!

if(selected(${region}, 'VHGMI') and ${mac_index_score} > 13, 'gt13', if(selected(${region}, 'VHGMI') and ${mac_index_score} <= 13, 'lt13', 'none of the above'))

 

- Josh Carlson
Kendall County GIS