In case you missed the announcement: Alteryx One is here, and so is the Spring Release! Learn more about these new and exciting releases here!

Alteryx Designer Desktop Discussions

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

How to add label based on condition

esabay
8 - Asteroid

Hi all sorry for the newbie question. How do do the desired output similar to the below. When Age 1 is greater than or equal to 5 but less than 10 label as ">5." When Age 1 is greater than or equal to 10 but less or equal to 29 label as ">10". When Age 1 is greater than 30 label as "30." Thank you

Data:

ItemAge 1Age 2
Rabbit1005
Horse50
Dog60
Cat83
Cow154
Man216
Toys106

 

Desired Output:

CategoryItemAge 1Age 2Label
Cake 1Rabbit1005> 30 days
Juice 1Horse50> 5 days
Juice 2Dog60> 5 days
Cake 2Cat83> 5 days
Juice 1Cow154> 10 days
Cake 2Man216> 10 days
Soda 1Toys106> 10 days
5 REPLIES 5
ed_hayter
12 - Quasar

In a formula tool:

 

IF [Age 1] >= 5 And [Age 1] < 10 then ">5" ELSEIF [Age 1] >= 10 AND [Age 1] <= 29 then ">10" ELSEIF [Age 1] > 30 then ">30" ELSE NULL ENDIF

 

Do note the gap at present between <= 29 and >30 which will result in any 30 entries returning NULL adjust as required (Same for less than 5).

 

Alternatively because condition tests are done sequentially we can reorder to simplify:

If [Age 1] > 30 then ">30"

ELSEIF [Age 1] >= 10 then ">10"

ELSEIF [Age 1] >= 5 then ">5"

ENDIF

 

Any entry that satisfies test 1 is never put through the following test so the second structure simplifies the process.

esabay
8 - Asteroid

Capture.PNG

  

Capture1.PNG

Hi @ed_hayter I am having the below errors when running the workflow. Apologies for the trouble but please help. Thank you

ed_hayter
12 - Quasar

Hi @esabay,

In Alteryx you cannot leave the else portion unspecified: try ELSE NULL() to assign any values that fail all tests to return NULL.

Rana_Kareem
9 - Comet

Hi @esabay 

 

You have to press (Add Column) first, then name it.

 

Add Column.png

 

 

Also, as @ed_hayter said, you cannot leave ELSE portion unspecified.

 

I hope that helps..

esabay
8 - Asteroid

Your solutions worked appreciate the help

Labels
Top Solution Authors