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}')))))
Solved! Go to Solution.
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
You need the else part always. You can just do this with empty string. You also had the check backwards.
if(${mosnumber} = 0, 'NA', '')
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
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):
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.
Wow, thanks for the tip! Didn't know that one, I would always just copy into an IDE
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
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.
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.
Still having the issue. I am using Survey123 Connect, should it be under the calculation column or relevant column?
If you're trying to calculate the value of the field, it should be in the calculation column.
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.