Alteryx Designer Desktop Discussions

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

Malformed If Statement

raviraghava
5 - Atom

I am receiving a malformed if statement error with the below formula. Can you explain why this is and how can I correct?

 

IF IsNull([Base_Part_Cal_1])THEN [Corp Part Nbr] ELSEIF FindString("-",[Corp Part Nbr]>2) THEN Substring([Corp Part Nbr],1,FindString("-",[Corp Part Nbr]-1))ELSE Substring([Corp Part Nbr],FindString("-",[Corp Part Nbr])+1,Length([Corp Part Nbr]-FindString("-",[Corp Part Nbr])) ENDIF

6 REPLIES 6
AngelosPachis
16 - Nebula

Hi @raviraghava ,

 

In your first Find string formula, the closing bracket should exclude the ">2", whilst also the field name should come first.

 

So now you have typed

 

ELSEIF FindString("-",[Corp Part Nbr]>2)

 

when it should have been

 

ELSEIF FindString([Corp Part Nbr],"-") >2.

 

The same goes for all following Findstring calls. As shown in the following image, the field's name should precede the target

 

AngelosPachis_0-1607887998915.png

 

 

Hope that helps,

 

Angelos

Qiu
21 - Polaris
21 - Polaris

@raviraghava 
I tried to run your formula, asides the points from @AngelosPachis , there is one more missing in red think.

 

IF IsNull([Base_Part_Cal_1])THEN [Corp Part Nbr] ELSEIF FindString([Corp Part Nbr],"-")>2

THEN Substring([Corp Part Nbr],1,FindString([Corp Part Nbr],"-")-1)

ELSE Substring([Corp Part Nbr],FindString([Corp Part Nbr],"-")+1,Length([Corp Part Nbr])-FindString([Corp Part Nbr],"-"))

ENDIF

 

Capture2.PNG

grazitti_sapna
17 - Castor

Hi @raviraghava , as suggested by @AngelosPachis  and @Qiu   there are some syntax errors in your 

formula as mentioned in red below:

 

IF IsNull([Base_Part_Cal_1])THEN [Corp Part Nbr] ELSEIF FindString("-",[Corp Part Nbr]>2) THEN Substring([Corp Part Nbr],1,FindString("-",[Corp Part Nbr]-1))ELSE Substring([Corp Part Nbr],FindString("-",[Corp Part Nbr])+1,Length([Corp Part Nbr]-FindString("-",[Corp Part Nbr])) ENDIF

 

Corrected formula in green:

 

IF IsNull([Base_Part_Cal_1])THEN [Corp Part Nbr] ELSEIF FindString([Corp Part Nbr],"-")>2
THEN Substring([Corp Part Nbr],1,FindString([Corp Part Nbr],"-")-1)
ELSE Substring([Corp Part Nbr],FindString([Corp Part Nbr],"-")+1,Length([Corp Part Nbr])-FindString([Corp Part Nbr],"-"))
ENDIF

 

 

I hope this helps.

 

Thanks.

 

 

 

Sapna Gupta
raviraghava
5 - Atom

Thanks for your clarification. Appreciated 

raviraghava
5 - Atom

Thanks for your detailed explanation with screenshots. Appreciated 

raviraghava
5 - Atom

Thanks Sapna for your detailed explanation, its really helped me to find the root cause of my issue.

Labels