Alteryx Designer Desktop Discussions

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

Labeling Based on Similar Criteria

sswift13
7 - Meteor

I am creating a column to label rows of data based on specific criteria. I want to say if "x = 1" then "seats" but if "x=1 and y=2" then [null].

The first part of my formula looks like

If REGEX_Match([CPSC], '^0110\d+.*\s*') then "Seats - EI" elseif regex_match([CPSC], '^0110\d+*\s*') and contains([Design Level Description], "COST ") then "" elseif......"

It carries on and labels some other rows based on different criteria.

 

However, it only is labeling with "Seats - EI", even if it meets the criteria to be null. I have tried swapping the order of the two but have come to the same result.

How can I label data with "Seats - EI" but then if it meets the second criteria, have it replaced with ""? Will it matter that my if statement continues and labels several other things afterwards?

2 REPLIES 2
apathetichell
18 - Pollux

 

 

It's impossible for your elseif statement to execute. Your first argument has already been fulfilled via statement 1 and the "and" clause means that only false entries for your first condition  will be looked at. Since it uses an AND it is by definition False.

 

Think of it this way.

 

Statement 1 is true. Then executes. Statement 1 is False.  Elseif requires Statement 1 to be True to execute. It cannot execute.

 

try swapping it to:

if regex_match([CPSC], '^0110\d+*\s*') and contains([Design Level Description], "COST ") then... elseif REGEX_Match([CPSC], '^0110\d+.*\s*') then...

 

 

 

Qiu
20 - Arcturus
20 - Arcturus

@sswift13 
I agree with @apathetichell , the order of the if statement should be interchanged or we do another way like below.

And I think your RegEx may be improved, since in ".*\s*", the "\s*" will be overrided by ".*" anyway, so "\s*" can removed.

0410-sswift13.PNG

Labels