If Statements: Unbalanced Brackets or parantheses

852
12
Jump to solution
01-10-2024 09:18 AM
EmilySpeck
New Contributor III

Hello,

Below is my IF function I am trying upload but I keep getting an error. Error is stating unbalanced parentheses or brackets.

if(selected(${pretype}, 'trash'),'NA'), if(selected(${pretype},'none'),'NA'), if(selected(${pretype},'other'),'${pretype_other}')))))

0 Kudos
2 Solutions

Accepted Solutions
rwrenner_esri
Esri Contributor

Additional parentheses are needed at the start of the subsequent if statements so they nest properly:

 

#can combine these lines into a single line for your XLSForm calculation
if(selected(${pretype}, 'trash'),'NA',
(if(selected(${pretype}, 'none'),'NA',
(if(selected(${pretype}, 'other'),'NA',${pretype_other})))))

 

 Hope this helps,

-Rylee

View solution in original post

0 Kudos
DougBrowning
MVP Esteemed Contributor

You need the else part always.  You can just do this with empty string.  You also had the check backwards.

if(${mosnumber} = 0, 'NA', '')

View solution in original post

0 Kudos
12 Replies
DougBrowning
MVP Esteemed Contributor

It is if( condition, true, false) so no parens until the end.

Also you can use or to make this simpler.

Also no quotes around field names and you are missing the final else.

For yours try

if(selected(${pretype}, 'trash') or (selected(${pretype},'none'), 'NA', if(selected(${pretype},'other'),${pretype_other}, need something in the else part here))

If these are the only 3 options then can make it even simpler

if(selected(${pretype}, 'trash') or (selected(${pretype},'none'),'NA', ${pretype_other})

Hope that helps

0 Kudos
abureaux
MVP Regular Contributor

Just a little tip for working with nested IF statements in S123 Connect. If you type "=" before your statement, you get Excels built-in logic helper and colour-coded brackets (most of the time):

abureaux_0-1704909127633.png

This can make matching brackets MUCH easier. EDIT: In case not everyone knows this with Excel, but the big benefit here is if you use the arrow keys to scroll over the brackets, Excel highlights both the bracket you scrolled over AND its sibling, so you should know exactly which brackets match up.

Just remember to delete the "=" when you are done, otherwise Excel will give you an error.

Katie_Clark
MVP Regular Contributor

Wow, thanks for the tip! Didn't know that one, I would always just copy into an IDE

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
0 Kudos
rwrenner_esri
Esri Contributor

Additional parentheses are needed at the start of the subsequent if statements so they nest properly:

 

#can combine these lines into a single line for your XLSForm calculation
if(selected(${pretype}, 'trash'),'NA',
(if(selected(${pretype}, 'none'),'NA',
(if(selected(${pretype}, 'other'),'NA',${pretype_other})))))

 

 Hope this helps,

-Rylee

0 Kudos
DougBrowning
MVP Esteemed Contributor

Should be no reason for parens around the if.  

But you still have the var in quotes there in what you posted.  

OP can be no quotes there  '${pretype_other}'

Or just use mine it should work.

0 Kudos
rwrenner_esri
Esri Contributor

As far as I know the number of parentheses does need to match when using the nested if statements method. In my initial reply I added them to match the ones OP had listed at the end, but they could also be removed from the end instead:

 

if(selected(${pretype}, 'trash'),'NA',
if(selected(${pretype}, 'none'),'NA',
if(selected(${pretype}, 'other'),'NA',${pretype_other})))

 

 Good catch on the quotation marks - thanks.

0 Kudos
EmilySpeck
New Contributor III

Still having the issue. I am using Survey123 Connect, should it be under the calculation column or relevant column? 

0 Kudos
rwrenner_esri
Esri Contributor

If you're trying to calculate the value of the field, it should be in the calculation column.

0 Kudos
abureaux
MVP Regular Contributor

Honestly, since others already fixed the nested IF statement that was provided, I didn't bother looking at it until now. But, going off of purely what's given, this is simpler:

if(selected(${pretype},'other'),${pretype_other},'NA')

No need for nested IF statements in this case.

0 Kudos