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

Alteryx Designer Desktop Discussions

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

Multi-Condition IF THEN ELSE statement

phil_budden
8 - Asteroid

Hi All,

 

I was wondering if anyone knows of a way to do a multi-condition 'IF THEN ELSE' statement in the formula tool,

 

I want to replace the contents of a string but only if two conditions are met, so for example:

 

Output Field

[FIELD 1]

 

IF [FIELD 2] = "X" and [FIELD 3] = "Y" THEN "Replacement Text" ELSE [FIELD 1] ENDIF

 

Alternitivly is there a better way to acheive this?

 

Thanks in advance...

14 REPLIES 14
JohnJPS
15 - Aurora

Your solution looks good to me.  I don't think you can simplify it further than that.

phil_budden
8 - Asteroid

Hi John,

 

Thanks for the quick response - when I was typing it as I did in the example I was getting an error about an unrecognised variable "and" so assumed there had to be another way to do this.  After you pointed out this was the correct way to do it I retyped the formula and this time it worked - must have been a typo in there!

 

Thanks again.

JohnJPS
15 - Aurora

Wild guess: a space in the "ENDIF" ... that one has gotten me often enough to be memorable.

phil_budden
8 - Asteroid

Hah, quite possibly Smiley Tongue

jdunkerley79
ACE Emeritus
ACE Emeritus

I tend to prefer the IIF for simple statements as have made that mistake too often!

phil_budden
8 - Asteroid
I've not used the IIF before, how does it differ from using IF THEN ELSE?
JohnJPS
15 - Aurora

In a nutshell:

 

IF c THEN t ELSE f ENDIF

 

(is the same as)

 

IIF(c,t,f)

 

jdunkerley79
ACE Emeritus
ACE Emeritus
It stands for inline if

IIF(<condition>,<true expression>,<false expression>)

Is a nice compact form.
phil_budden
8 - Asteroid
Great, less typing, will definitely make use of this going forward - thanks both
Labels
Top Solution Authors