How to add label based on condition
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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:
Item | Age 1 | Age 2 |
Rabbit | 100 | 5 |
Horse | 5 | 0 |
Dog | 6 | 0 |
Cat | 8 | 3 |
Cow | 15 | 4 |
Man | 21 | 6 |
Toys | 10 | 6 |
Desired Output:
Category | Item | Age 1 | Age 2 | Label |
Cake 1 | Rabbit | 100 | 5 | > 30 days |
Juice 1 | Horse | 5 | 0 | > 5 days |
Juice 2 | Dog | 6 | 0 | > 5 days |
Cake 2 | Cat | 8 | 3 | > 5 days |
Juice 1 | Cow | 15 | 4 | > 10 days |
Cake 2 | Man | 21 | 6 | > 10 days |
Soda 1 | Toys | 10 | 6 | > 10 days |
Solved! Go to Solution.
- Labels:
- Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
  
Hi @ed_hayter I am having the below errors when running the workflow. Apologies for the trouble but please help. Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @esabay
You have to press (Add Column) first, then name it.
Also, as @ed_hayter said, you cannot leave ELSE portion unspecified.
I hope that helps..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Your solutions worked appreciate the help
