alteryx Community

# Alteryx Designer Desktop Discussions

SOLVED

## Nested If Then Else Statement

5 - Atom

Is it possible to create an If Then Else statement that allows for more than three conditions?  For example, I need to create an If Then Else statement that looks at a number and determines if it falls in the following buckets; late, on-time, within 30 days, between 31 and 60 days, between 61 and 90 days, and greater than 90 days.

Thanks!!

11 REPLIES 11
15 - Aurora
Sure - just put the entire nested IF wherever needed, including its own ENDIF.... example: IF c THEN t ELSE (IF c THEN t ELSE f ENDIF) ENDIF.

The parnthese aren't needed either - just there for clarification. Hope that helps!
12 - Quasar

You should also check out the tile tool for quickly creating custom range bands like that.  Assuming you have (or used a formula to create) a field that is numeric (ex. days late), then in the tile tool, you can pick 'Manual' for the tile method then just type your cutoffs.

20 - Arcturus

If arg1 then result1 elseif

arg2 then result2 elseif

arg3 then result3 else

default

endif

with dates you can use <= as once 30 days is used in an argument , when you check for 60 days the result must be between 30 and 60.

Just a thought for you.

Thanks,

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
7 - Meteor

Hello there!

Good topic

I have a statement that will create a column of day ranges but it will only create 2 ranges for some reason.

It seems to like only the  "Over 180" and the "0-30"  I have several others that just wont compute out.

Also the 2 groupings are not lining up with the days they are supposed to be lined up with

The [Days Open] field is the result of 2 diff dates calculated in 'days'

If [Days Open] >= '180' THEN "Over 180" elseif  [Days Open] >= '90' THEN "90-180" elseif  [Days Open] >= '60'  THEN "60-90" elseif  [Days Open] >= '40'  THEN "40-60" elseif  [Days Open] >= '30' THEN "30-40" elseif  [Days Open] >= '0' THEN "0-30" Else [Days Open] ENDIF

Any help would be extremely appreciated!

7 - Meteor

You don't need single quotes around your conditions. Doing so interprets you difference of date as a number, and then your nested IF THEN ELSEIF statement is working

7 - Meteor

Perfect and Thank you!

5 - Atom

I have a CSV file with column PDPDESC which has values I (stands for Inconsistent), S( stands for Satisfactory) and L (Leading Performance). Below was a formula I added to my existing workflow to include this particular metric:-

IF [PDPDESC]="I" THEN "INCONSISTENT PERFORMANCE" ELSE(IF [PDPDESC]="S" THEN "SATISFACTORY PERFORMANCE" ELSE (IF [PDPDESC]="L" THEN "LEADING PERFORMANCE" ELSE "N/A" ENDIF) ENDIF

It still gives me Parse Error when I try IF c THEN t ELSEIF c2 THEN t2 ELSE f ENDIF. Then tried using the above formula but gives me "Unmatched ( " error.

Need some help on this

7 - Meteor

You have 3 IF but only 2 ENDIF
You opened 2 (, but only closed one;

Try indenting your code. You'll see not all is closed :)

IF [PDPDESC]="I"
THEN "INCONSISTENT PERFORMANCE"
ELSE(
IF [PDPDESC]="S"
THEN "SATISFACTORY PERFORMANCE"
ELSE (
IF [PDPDESC]="L"