Early bird tickets for Inspire 2023 are now available! Discounted pricing closes on January 31st. Save your spot!

Alteryx Designer Discussions

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

Need Help

MMalkar
5 - Atom

Hi All,

I am very new to the Alteryx, can anyone help me with below formula 

if [Age] < "2" THEN "0-1"elseif(Age) >2 & <6 then "2-5" elseif (Age) >6 & <10 then "6-10"

4 REPLIES 4
atcodedog05
22 - Nova
22 - Nova

Hi @MMalkar 

 

The formula would be converted to something like this

 

If [Age] is string

 

 

IF [Age] < "2" THEN "0-1" 
ELSEIF [Age] >= "2" and [Age]<"6" THEN "2-5" 
ELSEIF [Age] >= "6" and [Age]<"10" THEN "6-10" 
ELSE Null() ENDIF

 

 

 

or If [Age] is number

 

IF [Age] < 2 THEN "0-1" 
ELSEIF [Age] >= 2 and [Age]<6 THEN "2-5" 
ELSEIF [Age] >= 6 and [Age]<10 THEN "6-10" 
ELSE Null() ENDIF

 

Hope this helps 🙂 

Luke_C
17 - Castor

Hi @MMalkar 

 

Do you have sample data? Are you getting an error? At first glance you might need some updates to the syntax. Looks like you're trying to use numeric operators on strings which might not give you what you want (<"2"). Try the below, make sure your age field is numeric.

 

IF [Age] < 2 Then "0-1"

Elseif [Age] >=2 AND [Age] <6 Then "2-5"

elseif [Age] >=6 AND [Age] <10 then "6-10"

else null()

endif

MMalkar
5 - Atom

MMalkar_0-1622573886909.png

 

ellen-wiegand
Alteryx
Alteryx

you need an ELSE statement any time you use a conditional. 

 

IF [risk age]<2 

THEN "0-1"

ELSE {put your alternate option here}

ENDIF

 

Also, pay attention to your data types in your incoming data. If [risk age] is a string, you will need to change it to a numeric format since you're using a mathematical function (less than)

 

You can see the data type by adding a browse tool, or clicking the "metadata" box in the results window.

 

Also note that your new column [Age bucket] has to be a string because of your quotes. You may want it to be numeric depending on what you're doing with it later. 

 

Labels