Alteryx Designer Desktop Discussions

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

Adding Value to a new column based on values in two other columns

amorej
5 - Atom

I am trying to think of a way to assign a value based on two other columns.  See below.  This site is great.  Thank you in advance for your help

 

PartnerCategory Product Code
NorthWinter Red
SouthSummer Yellow
EastSummer Magenta
NorthSummer Orange
SouthFall Violet
EastFall White
NorthWinter Red
WestFall Purple
SouthSummer Yellow
EastSummer Magenta
SouthSpring Pink
WestFall Purple
NorthSpring Blue
    
    
If Partner=North and Category =Winter then Product Code = Red
If Partner=North and Category =Summer then Product Code = Orange
etc…...   
2 REPLIES 2
DataNath
17 - Castor

Hey @amorej, you were just about there with what you had typed out! You first need to bring a Formula tool into your data stream and give the new expression a name (or you can edit an existing one), from the pane under 'Output Column'. There's just a few key tweaks to format the expression as needed for Alteryx:

 

1 - Wrap field names in square brackets e.g. Partner ought to be [Partner]

2 - The values that you are checking for (North, South, Summer, Winter etc) need to be within quotes, so [Partner] = "Winter" or [Partner] = 'Winter' for example. If you're checking numeric fields then you don't use quotes, would just be the number itself like [Total] = 100

3 - If there are multiple possible outcomes (i.e. a large list of Partner/Category combinations), then you use 'elseif' to essentially restart your if statement each time

4 - To finalise your if statement, you need to provide an 'else' which is essentially saying 'if my values don't match any of the combinations to output the outcomes I've listed above, just do this...' (in my example this is 'White', which is applied to everything where the values don't match a specific combination I've set out)

5 - Use 'endif' to actually finish your if statement

 

DataNath_0-1661463585117.png

 

More great resources here if you want to learn more about expressions in Alteryx: https://community.alteryx.com/t5/Interactive-Lessons/tkb-p/interactive-lessons/label-name/writing%20...

binuacs
20 - Arcturus

@amorej One way of doing this with the If Else condition

 

binuacs_0-1661464120855.png

 

Labels