Alteryx Designer Desktop Discussions

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

IF THEN ELSE Formula with startswith - not returning value

aurorab
5 - Atom

Hello,

 

I'm fairly new to Alteryx. I'm preparing a workflow and am near the end.

 

I am attempting to create an IF THEN ELSE function that essentially says "If the Purchase Order column starts with ___, then change the Customer Name column to ___, or else keep as ____". There are four criteria that I need for this function, and I have all four separated into their own functions, and they are identical except for the "starts with" criteria. There are no errors within the functions, and when I run the workflow, only one criteria changes the customer name to what it needs to be.

 

Two of the functions have "starts with" data that are letters and numbers, one is just numbers, and the function that worked is just letters.

 

Is the reason for the only letters function working because it only contained letters? If so, what is the best way to also return the remaining three functions?

 

 

 

 

5 REPLIES 5
AngelosPachis
16 - Nebula

Hi @aurorab ,

 

So the reason you are only able to see the results of the last function is because, well it comes last. All of your functions are probably working and doing something, but because all 4 of them have the same name, that means that they overwrite each other. 

 

Essentially, Allteryx applies the first function and returns some results, the looks at the second function and returns the results which overwrite those of the first function.

 

What you can do to see how each of your function works is to create new columns. So instead of giving the same field name, you can name them as CUST_NAME 1, CUST_NAME 2 and so on and pick what works for you.

 

Hopefully that makes sense and you will be able to get what you are looking for, please let me know if you have any other questions

aurorab
5 - Atom

Thanks for that solution, when I add in additional columns with 1 2 etc, the formula looks like it would work!

 

Going off of this - is it possible for me to just combine the "starts with" criteria I was initially splitting up into one formula?

 

I attempted combining all criteria into one function, and it seems like it would work as long as I separate each criteria using OR. But now I am getting a "malformed function call" error.

 

IF StartsWith([PURCHASE_ORDER], "A1" OR "A2" OR "1234" OR "AAAA"

THEN "New"

ELSE " Original"

ENDIF

 

Right before the THEN is where I am getting this error.

vizAlter
12 - Quasar

Hi @aurorab — Welcome to the Alteryx Discussions!

Try this solution... you can solve this in two ways;

1) Use your StartsWith expression like below:

 

IF StartsWith([PURCHASE_ORDER], "A1")
	OR  StartsWith([PURCHASE_ORDER], "A2")
	OR  StartsWith([PURCHASE_ORDER], "1234")
	OR	 StartsWith([PURCHASE_ORDER], "AAAA") THEN 
	"New" 
ELSE 
	"Original" 
ENDIF

 

vizAlter_0-1605847674552.png

 

2)  Use a RegEx expression:

 

IF REGEX_Match([PURCHASE_ORDER], "^(A1|A2|1234|AAAA).*$") THEN 
	"New" 
ELSE 
	"Original" 
ENDIF

 

vizAlter_1-1605847759689.png

 

If this assists please mark the answer "Solved", if not let me know!

grazitti_sapna
17 - Castor

Hi @aurorab,

 

Try it like this.

 

IF StartsWith([PURCHASE_ORDER], "A1")
	OR  StartsWith([PURCHASE_ORDER], "A2")
	OR  StartsWith([PURCHASE_ORDER], "1234")
	OR	 StartsWith([PURCHASE_ORDER], "AAAA") THEN 
	"New" 
ELSE 
	"Original" 
ENDIF

 

I hope it helps. 

Sapna Gupta
vizAlter
12 - Quasar

@aurorab -- Thank you!

Labels