Multiple if, for multiple values

670
9
Jump to solution
11-28-2022 03:08 AM
Iron_Mark
New Contributor III

Hi,

I am failing calculating multiple if and I can't understand why.

I tried multiple syntax but this one maybe will let you understand better what I would like to do.

I want to: if select a productname and a surface it should return a value, otherwise another, in the same way, if another product is selected with the same surface, it has to return another value, otherwise again another value.

if(selected(${prod}, 'product1') and selected(${surface}, 'surface1'), '10', '20'), if(selected(${prod}, product2') and selected(${surface}, 'surface2'), '100', '200')

I always get an error. Any help would be appreciated.

Thank you in advance

0 Kudos
1 Solution

Accepted Solutions
JenniferAcunto
Esri Regular Contributor

You have 4 if statements, so you need to have 4 closing parenthesis at the end. 

if(selected(${prod}, 'Roundup_ProActive') and selected(${surface}, 'surface1'), '10',
if(selected(${prod}, 'product1') and selected(${surface}, 'surface2'), '20', if(selected(${prod}, 'product2') and selected(${surface}, 'surface1'), '100', if(selected(${prod}, 'product1') and selected(${surface}, 'surface2'), '200', '11'))))

- Jen

View solution in original post

9 Replies
JenniferAcunto
Esri Regular Contributor

The second if statement is technically a part of the first if statement (it is the 'else'). So you will need to move the closing parenthesis for the first if statement to the very end. 

if(selected(${prod}, 'product1') and selected(${surface}, 'surface1'), '10', if(selected(${prod}, product2') and selected(${surface}, 'surface2'), '100', '200'))

- Jen
0 Kudos
Iron_Mark
New Contributor III

Hi Jennifer,

By doing this it sais that "if requires 3 arguments. Only 4 provided"

0 Kudos
JenniferAcunto
Esri Regular Contributor

you need your first if condition (is this true), your second if condition (if the first one is false, is this one true), and then your default answer (if both are false provide this)....so those are the three arguments you need. Make sure you don't have anything else in your calculation.

- Jen
0 Kudos
Iron_Mark
New Contributor III

if(selected(${prod}, 'Roundup_ProActive') and selected(${surface}, 'surface1'), '10', if(selected(${prod}, 'product1') and selected(${surface}, 'surface2'), '20', if(selected(${prod}, 'product2') and selected(${surface}, 'surface1'), '100', if(selected(${prod}, 'product1') and selected(${surface}, 'surface2'), '200', '11'))

 

It only works the first part (with a non sense element such 11):

if(selected(${prod}, 'product1') and selected(${surface}, 'surface1'), '10', if(selected(${prod}, 'product1') and selected(${surface}, 'surface2'), '20', '11'))

 

Really don't know what to do.

0 Kudos
JenniferAcunto
Esri Regular Contributor

You have 4 if statements, so you need to have 4 closing parenthesis at the end. 

if(selected(${prod}, 'Roundup_ProActive') and selected(${surface}, 'surface1'), '10',
if(selected(${prod}, 'product1') and selected(${surface}, 'surface2'), '20', if(selected(${prod}, 'product2') and selected(${surface}, 'surface1'), '100', if(selected(${prod}, 'product1') and selected(${surface}, 'surface2'), '200', '11'))))

- Jen
Iron_Mark
New Contributor III

Jen

 

We did it! 😄 

Thanks a million! In the end I just put the 4 parenthesis and it worked.

Big Hug

0 Kudos
JenniferAcunto
Esri Regular Contributor

YAY

- Jen
GregKeith
Occasional Contributor III

What are you doing this in, Arcade, Survey123, etc? You have a default else value (20) in your first statement, if the condition is not true, so the second if statement would make no logical sense as an alternative to the first; also, can't be on the same line, although unclear if that's how it's set in your code. 

What it appears you're doing is setting some value such that
if selection = Jedi then Light, else Dark
and also saying
if selection = human, then organic, else droid

This can work as separate if statements, but if you're setting one value/text/etc, the second one will always overwrite the first no matter what. You might look at nesting them.

0 Kudos
Iron_Mark
New Contributor III

Hi Greg,

Nice creativity with the example.

I am doind this with survey123 as the community suggest. I am completely stuck with this now..

this is the further I could go.....

if(selected(${prod}, 'product1') and selected(${surface}, 'surface1'), '10', if(selected(${prod}, 'product1') and selected(${surface}, 'surface2'), '20', '11'))

By doing this it works (the alternative value 11 doesn't make sense, but at least make it works).

Still it is missing the whole second part with product2 and surface2. If I copy and paste the first part changing the names it gives an error....

0 Kudos