nesting if AND formula in XLSform.

777
3
01-02-2020 12:11 PM
Alex_Dale
New Contributor

I am having trouble nesting multiple if AND statements in an XLSform for Survey123. 

I am getting the follwing error: cannot handle function 'if' requires 3 arguments. Only 1 provided.

Here is my formula:

if(AND(${homelessness}="1to2yrs", ${mhDis}="Yes",1,if(AND(${homelessness}="1to2yrs", ${PhyDevOther}="Yes",1,if(AND(${homelessness}="1to2yrs", ${AlcDrugs}="Yes",1,if(AND(${homelessness}="1to2yrs", ${HIVAIDS}="Yes",1,if(AND(${homelessness}="other", ${mhDis}="Yes",1,if(AND(${homelessness}="other", ${PhyDevOther}="Yes",1,if(AND(${homelessness}="other", ${AlcDrugs}="Yes",1,if(AND(${homelessness}="other", ${HIVAIDS}="Yes",1,if(AND(${homeless_times}="4", ${mhDis}="Yes",1,if(AND(${homeless_times}="4", ${PhyDevOther}="Yes",1,if(AND(${homeless_times}="4", ${AlcDrugs}="Yes",1,if(AND(${homeless_times}="4", ${HIVAIDS}="Yes",1))))))))))))))))))))))))

Any help is greatly appreciated.

0 Kudos
3 Replies
Jim-Moore
Esri Regular Contributor

Hi Alex

If statements require three arguments: a condition; the result if the condition is true; and the result if the condition is false. It looks like the final false argument is missing (i.e. what to return if all conditions are false).

Also, the XLSForm syntax for and statements is to use the word "and" between two expressions. For example:

${homelessness}='1to2yrs' and ${mhDis}='Yes'

XLSForm functions are detailed here: Formulas—Survey123 for ArcGIS | Documentation 

Hope this helps.

Cheers,

Jim

0 Kudos
Alex_Dale
New Contributor

Thank you Jim,

The new syntax somewhat worked. Now, however, the first IF function

overrides the rest of the nested IF functions:

if($="1to2yrs"and $="Yes",1,2) or if($="1to2yrs"and $="Yes",1,2) or if($="1to2yrs"and $="Yes", 1,2) or if($="1to2yrs"and $="Yes",1,2) or if($="other"and $="Yes",1,2) or if($="other"and $="Yes",1,2)

or if($="other"and $="Yes", 1,2) or if($="other"and $="Yes",1,2) or if($="Yes"and $="Yes",1,2) or if($="Yes"and $="Yes",1,2)or if($="Yes"and $="Yes",1,2)or if($="Yes"and $="Yes",1,2)

Any thoughts?

Alex Dale

Data Manager

Partners In Care, Oahu’s Continuum of Care

200 North Vineyard Boulevard, Suite 210

Honolulu, HI 96817

Phone: (808) 543-2242

Email: adale@auw.org

www.partnersincareoahu.org

TOGETHER, WE CAN END HOMELESSNESS

Partners in Care’s mission is to eliminate homelessness through open and

inclusive participation and the coordination of integrated responses.

0 Kudos
Jim-Moore
Esri Regular Contributor

Hi Alex

The way you had nested the if statements in your original post looks correct, besides the syntax for the and function and the missing false argument for the final if statement. As a simple example:

if(${fruit}='banana','yellow',if(${fruit}='apple','green',if(${fruit}='strawberry','red','no fruit selected')))

Hope this helps

Cheers,

Jim

0 Kudos