Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

If conditional with multiple criteria

Rob48
8 - Asteroid

I'm using the Formula tool on the following type of data:

Acct

XXX-AAA

XXX-BBB

XXX-CCC

XXX-DDD

XXX-EEE

YYY-AAA

YYY-BBB

 

if the data has "AAA" (XXX-AAA and YYY-AAA are the targets) i want one result, if the data has "XXX" but not "AAA" then I want another result (the match is all the data starting with XXX except XXX-AAA)

 

i broke it up into two consecutive formula tools, the first one worked and went like this:

 

IF Contains([Acct], "AAA") THEN t ELSE f ENDIF

 

this worked, got the results i needed for XXX-AAA and YYY-AAA

 

 but then i added a second tool and wrote like this:

 

IF Contains([Acct], "XXX") and !Contains([Acct], "AAA") THEN t ELSE f ENDIF

 

this is not working -- it does what i want with the XXX data but invalidates what i did with the AAA data in the first tool.

 

can i either write this all in one formula tool, or in consecutive tools such that the formula in the second tool does not invalidate the first tool's formula? I could probably split them out with a filter and then recombine, but this seems like too many steps.

1 REPLY 1
echuong1
Alteryx Alumni (Retired)

You can write multiple conditions in one statement. Your additional conditions would have ELSEIF.

 

For example:

 

IF Contains([Acct], "XXX") and !Contains([Acct], "AAA") THEN t2

ELSEIF Contains([Acct], "AAA") THEN t

ELSE f ENDIF

Labels