community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

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

Chain Else if using Or

Highlighted
Atom

Hello,

 

Trying to get the following formula to work in order to categorize data, but I keep getting a "Malformed If Statement" error:

 

if [buyer] = "Zone_1" or "Zone_2" or "Zone_3" then "North Region" else if [buyer] = "Zone_A" or "Zone_B" or "Zone_C" then "East Region" else if "Zone1A" or "Zone_2B" or "Zone_3C" or "Zone_4D" or "Zone_5E" or "Zone_6F" or "Zone_7G"  then "West Region" else if [buyer] = "ABCD" or "1234" or "A1B2C3D4" then "South Region" else "" endif

 

I set the data type to String (same as the buyer field), not sure what I am doing wrong. The error seems to be focused on how I am ending the if statement though I could be misunderstanding that. Any assistance is appreciated.

Bolide

Hi @al2508 ,

 

If this is copied out of the formula tool, then the first thing I see is that you have a space between else and if.  You are also missing a field (in blue below).  Try this:

 

if [buyer] = "Zone_1" or "Zone_2" or "Zone_3" then "North Region" elseif [buyer] = "Zone_A" or "Zone_B" or "Zone_C" then "East Region" elseif  [buyer] = "Zone1A" or "Zone_2B" or "Zone_3C" or "Zone_4D" or "Zone_5E" or "Zone_6F" or "Zone_7G"  then "West Region" elseif [buyer] = "ABCD" or "1234" or "A1B2C3D4" then "South Region" else "" endif

 

A simpler way to write this would be:

 

if [buyer] IN ("Zone_1", "Zone_2", "Zone_3") then "North Region" ELSEIF [buyer] IN ("Zone_A", "Zone_B", "Zone_C") then "East Region" elseif  [buyer] IN ("Zone1A", "Zone_2B", "Zone_3C", "Zone_4D", "Zone_5E", "Zone_6F", "Zone_7G")  then "West Region" elseif [buyer] IN ("ABCD", "1234", "A1B2C3D4") then "South Region" else "" endif

Labels