Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

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

IF ELSEIF error - malformed - IN A FILTER


I want to filter out a few ranges of data. I'm using the Filter tool with an IF/ELSEIF - but getting error. 

What is wrong with this IF ELSEIF?


IF [Enc - MS DRG] >= 765 OR <= 795 THEN f
ELSEIF [Enc - MS DRG] >= 876 OR <= 897 THEN f
ELSEIF [Enc - MS DRG] >= 945 OR <= 946 THEN f
ELSEIF [Enc - MS DRG] >= 949 OR <= 950 THEN f


Enc - MS DRG is data type of Double.


Error is:

Parse Error at Char (25): Malformed IFStatement

ACE Emeritus
ACE Emeritus

You'll need to provide your variable in both the greater than and the less than sides of the OR:


IF [Enc - MS DRG] >= 765 OR [Enc - MS DRG] <= 795 THEN f
ELSEIF [Enc - MS DRG] >= 876 OR [Enc - MS DRG] <= 897 THEN f
ELSEIF [Enc - MS DRG] >= 945 OR [Enc - MS DRG] <= 946 THEN f
ELSEIF [Enc - MS DRG] >= 949 OR [Enc - MS DRG] <= 950 THEN f



Now, I'm getting an error  - Parse Error at Char (55): Unknown variable 'f'


This is a Filter so I want True False to divert the data between those that are true and false.

Do I need a parameter to hold the T or F? 

I thought since it was a filter it would know this?



ACE Emeritus
ACE Emeritus

Two approaches - you could replace them with "f" in quotes, so that it's a string rather than the unassigned variable f; (same with "t" vs. t)



Or, probably better: you can set the Output Field type to "Bool ", and in the conditional logic, replace the f with 0, and the t with 1:


IF [Time] >= 765 OR [Time] <= 795 THEN 0
ELSEIF [Time] >= 876 OR [Time] <= 897 THEN 0
ELSEIF [Time] >= 945 OR [Time] <= 946 THEN 0
ELSEIF [Time] >= 949 OR [Time] <= 950 THEN 0


That way - as you describe your wishes, you can treat the variable downstream as a boolean.


Hope that helps! 

Alteryx Certified Partner
Alteryx Certified Partner

First, are you sure this IF statement is doing what you want?


IF [Enc - MS DRG] >= 765 OR [Enc - MS DRG] <= 795 is going to be true for all numbers. Any real number that you can name is either greater than 765 or less than 795. I think you are looking for an AND statement here if you want to find all numbers between 765 and 795 inclusive.


Second, if you are using a filter statement, you don't need to mark things as True or False. The rows flagged TRUE will come out the T output from the tool. The rows flagged FALSE will come out the F output from the tool.


([Enc - MS DRG] >= 765 AND [Enc - MS DRG] <= 795) OR
([Enc - MS DRG] >= 876 AND [Enc - MS DRG] <= 897) OR
([Enc - MS DRG] >= 945 AND [Enc - MS DRG] <= 946) OR

([Enc - MS DRG] >= 949 AND [Enc - MS DRG] <= 950)


The statement above should accomplish your goal and everything TRUE will come from the T output on the Filter Tool.





You are correct on all points.