Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

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

IF AND and OR statements

Lili7891
7 - Meteor

Hi all, 

Hoping this is a simple one and I am just going data blind, but trying to do a multi row formula to update my "work" column per the sample example below

 

workgrade(replaces) work
ABCManager 
ABCBoss 
ABCSenior 
ABCManager 
ABCTrainee 
ABCJunior 
DEFManager 
DEFJunior 

 

I tried

 

IF [Work] = "ABC" AND
[Grade] = "Boss" OR
[Grade] = "Senior" OR
[Grade] = "Manager" THEN
"ABC (MANAGEMENT)"
ELSEIF
[Work] = "ABC" AND
[Grade] = "Trainee" OR
[Grade] = "Junior" OR
THEN
"ABC (JUNIORS)"
ELSE [Work]
ENDIF

 

But it doesn't look like it's working as it seems to be only referencing grade and therefore updating every work column with the result based on grade only and not work. I want the result to look like this

 

workgrade(replaces) work
ABCManagerABC (Management)
ABCBossABC (Management)
ABCSeniorABC (Management)
ABCManagerABC (Management)
ABCTraineeABC (Juniors)
ABCJuniorABC (Juniors)
DEFManagerDEF
DEFJuniorDEF

 

But I seem to be getting this

workgrade(replaces) work
ABCManagerABC (Management)
ABCBossABC (Management)
ABCSeniorABC (Management)
ABCManagerABC (Management)
ABCTraineeABC (Juniors)
ABCJuniorABC (Juniors)
DEFManagerABC (Management)
DEFJuniorABC (Juniors)

 

Can't work out how to fix this but the ANDs and ORs always throw me. I think if I switch everything to OR it had the same effect.

2 REPLIES 2
DataNath
17 - Castor
17 - Castor

Hey @Lili7891 - I believe this is what you're looking for?

 

DataNath_0-1666187626504.png

 

The key to fixing your existing statement is adding brackets to your if statement - around your 'OR' possibilities - so that these checks are done alongside the [Work] condition, rather than as an alternative, which was previously throwing the expression off.

 

However, another way of tackling this (shown above), that is also more efficient when you have a long list of 'OR "X" OR "X"....' is using the IN function, whereby you just include a list in the ('A','B','C'...) format.

 

Keeping your original 'OR' lists, adding the brackets:

 

DataNath_1-1666187711963.png

binuacs
21 - Polaris

@Lili7891 One way of doing this

 

binuacs_0-1666189834241.png

 

Labels
Top Solution Authors