Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Nested If statements to check second condition only if first condition is met

Vaib
8 - Asteroid

How to write a nested if statement in formula tool to check the second condition only if the first condition is true or false.

Example: Condition 1: If country = USA is true then check
Condition 2: State = Oregon or New Jersey
If Condition 1 is not met then "Not Valid"

4 REPLIES 4
messi007
15 - Aurora
15 - Aurora

@Vaib,

 

Please see below how you can do it:

 

messi007_0-1616692619492.png

Attached the workflow,

If this solve the issue please mark it as solved. It will help others.

 

Regards,

ChrisTX
15 - Aurora

What should the value be if country is not USA?  Try this

 

IF [country] = "USA" 

THEN

  IF [State] IN ("Oregon", "New Jersey")

    THEN "valid"

    ELSE "Invalid"

  ENDIF

ELSE Null()

ENDIF

 

Here is a list of all functions: https://help.alteryx.com/current/designer/functions

 

Chris

jvansistine
9 - Comet

Some other alternatives to those presented, depending on your use case.

 

If Country = USA AND State in (Oregon, New Jersey) then ....

ElseIf Country = USA then ....

Else ...

End

 

The important thing to remember about using nested IF/THEN/ELSE or CASE logic is that it is not recursive at all.  Every row of data can only match 1 condition, and it will get a value as soon as it matches one.  So, it's often helpful to put the most restrictive conditions first and expand from there.

 

You could also use a filter tool to separate your data into 2 streams based on Country = USA logic.  Use the "True" stream to do your next validation on the states.  This would also give you the opportunity to do any validation on the non-USA rows separately.  You could use a Union tool to put the 2 streams back together once the two streams have been categorized accordingly.

 

Hope this helps!

-Jim

 

Vaib
8 - Asteroid

Thank you everyone for the solution!

Labels