Important Community update: The process for changing your account details was updated on June 25th. Learn how this impacts your Community experience and the actions we suggest you take to secure your account here.

Alteryx Designer Desktop Discussions

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

If statements with multiple columns

cklint
7 - Meteor

Hi everyone, lets say I want to make an If statement like the following

 

If [Column Z] = "H" and [Column A] =  ([column B],[column C],[column D],[column E],[column F],[column G],[column H]) then "X" else "Y" endif

 

How would the syntax work for this in alteryx? Without doing some sort of gigantic string of elseIf's?

 

The idea of course being that if column Z contains the value "H" and column A is equal of any one of lets say 10-20 columns.

 

Thanks

5 REPLIES 5
cmcclellan
13 - Pulsar

I would do this

If [Column Z] = "H" and (
[Column A] = [column B]
or [Column A] = [column C]
or [Column A] = [column D]
or [Column A] = [column E]
or [Column A] = [column F]
or [Column A] = [column G]
or [Column A] = [column H]
) 
then "X" 
else "Y" 
endif

 

It feels a bit long, but you're only writing it once :) 

 

AGilbert
11 - Bolide

Here is another way using your original expression. Instead of testing if A is equivalent to a list use the 'in' operator. 

 

if_in.png

cmcclellan
13 - Pulsar

Nice solution @AGilbert I was thinking about IN when I posted mine, but I didn't have the time to test.

 

Your filter is interesting though, I never write the full IF syntax in a filter, I just use the raw condition like this (but either way works):

 

[Z] = 'H' and [A] in ([B],[C],[D],[E],[F],[G])

 

AGilbert
11 - Bolide

@cmcclellan I agree that the full if statement is unnecessary. I should take time to tighten up my logic blocks but sometimes the ideas just fly, ya know!?

cklint
7 - Meteor

Thanks @AGilbert , an "IN" statement is exactly what I was looking for.

Labels