Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

IF and AND multiple grouping

BarleyCorn
8 - Asteroid

I have actual age in data set. I would like to create a new variable called Age Group. So, if [Age] => 25 and < 35, then Age Group = 25-34 Else, if [Age] => 35 and <45 then Age Group = 35-44, Else, ...and so forth to [Age] > 64, Age Group = "65+"

 

Straight forward market research calc, just struggling with Formula tool logic??

 

Thanks

7 REPLIES 7
MarqueeCrew
20 - Arcturus
20 - Arcturus

Hi @BarleyCorn,

 

IF age < 25 Then "24 or Less' ELSEIF
AGE < 35 then ' 25 to 34' ELSEIF
age < 45 then ' 35 to 44' ELSE
"Just getting started"
ENDIF

The problem that you were having is:

 

IF. Age > 24 AND Age < 35 Then '25 - 34' ELSEIF

 

you need to structure the AND with two complete comparisons. 

 

I simplified the statements because once you test for the lower range you don't have to test it again. Once you have eliminated under 25 when you test for under 35, then the group must be 25 to 34. 

 

I I hope that this helps?

 

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
BarleyCorn
8 - Asteroid

Hi MarqueeCrew,

 

The following still gets an error?

 

IF [Age] < 25 then "24 or less" ELSEIF

[Age] < 35 then "25 to 34" ESLEIF

[Age] < 45 then "35 to 44" ELSEIF

[Age] < 55 then "45 to 54" ESLEIF

[Age] < 65 then "65+" ELSE

ENDIF

 

Getting "Parse error at Char(167) Un known variable "ENDIF" ??

 

 

DultonM
11 - Bolide

Hi @BarleyCorn!

 

2 things and then you should have it. 1) You have 2 spelling errors (both cases "ESLEIF" instead of "ELSEIF") and 2) you need to have something between the last ELSE and the ENDIF. In other words, what do you want the Formula to return if none of the other IFs are met (like when age is > 65)?

MarqueeCrew
20 - Arcturus
20 - Arcturus
IF [Age] < 25 then "24 or less" ELSEIF
[Age] < 35 then "25 to 34" ELSEIF
[Age] < 45 then "35 to 44" ELSEIF
[Age] < 55 then "45 to 54" ELSEIF
[Age] < 65 then "55 to 64" ELSEIF
[Age] > 64 then "65+" ELSE "UNKNOWN" ENDIF
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
BarleyCorn
8 - Asteroid

Hi, Thanks for your help, but still no luck so I have attached Workflow, I have tried everything!!

 

Thanks

 

MarqueeCrew
20 - Arcturus
20 - Arcturus

@BarleyCorn,

 

A few fixes:

 

New variable is "Vstring"

final ELSEIF is ELSE

 

Very Close!

 

The module is attached.

 

Cheers,

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
BarleyCorn
8 - Asteroid

Thats it!! - Thanks Mark!

 

Labels