Alteryx Designer Desktop Discussions

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

Filling a new Column based on elements of other columns based on "logic" ?

Gio
6 - Meteoroid

I am trying to fill a new column with String values based on another column (ie the logic).  In Excel, I would build a reference table and do a lookup.  For arguments sake, lets say i have a list of individual food items:

 

ItemMeal (new column)
Bacon 
Eggs 
Sandwich 
Steak 

 

I want to write a formula to assign the meal.  I can get it to run on one item using the following assigned to my new meal column:

 

IF ([Item] = "Bacon") THEN "Breakfast" Else "Bacon" ENDIF

 

Entering the name in the new column for failures will help identify when the rules need updating...I just can't figure out how to get all of the rules in one spot.

 

Thanks

 

Gio

4 REPLIES 4
NickSm
Alteryx
Alteryx

Hey @Gio ,

 

You'd be plenty able to do things as you've done prior by using a reference table in another Input tool and by using a Join or Find and Replace based on your common identifier.

 

Otherwise you're on the right track that within a Formula tool you can build the conditional logic into an expression.  The more efficient way to do things will likely depend on how many potential entries you're working with.

 

clipboard_image_0.png

 

 

CharlieS
17 - Castor
17 - Castor

I put together a couple options in the attached example. It all depends on how you'd like to input/manage your meal assignments. if you have an example of how you'd like to input that, I'm sure we can make it work.

JosephSerpis
17 - Castor
17 - Castor

Hi @Gio this syntax should work in the formula tool If [Item]="Bacon" then "Breakfast" ELSEIF [Item]="Eggs" THEN "Breakfast" ELSEIF [Item]="Sandwich" then "Lunch" ELSEIF [Item]="Steak" THEN "Dinner" ELSE "" ENDIF

 

or even

 

If [Item] In ("Bacon","Eggs") then "Breakfast" ELSEIF [Item]="Sandwich" then "Lunch" ELSEIF [Item]="Steak" THEN "Dinner" ELSE "" ENDIF

Gio
6 - Meteoroid

Thanks all.  The Elseif listing worked great. 

 

I appreciate that it would probably be a lot easier to keep a table elsewhere (I have about 30 items on my listing...), but I want all of the maintenance in one place.


Thanks Again!!

 

Gio

Labels