Hi Alteryx Community,
I'm having difficulty when using if statement , I still get parse error.
Kindly help me to resolve this concerns.
IF [Length]=6 THEN [Business Area]+[Doc Nbr]
ELSEIF [Length]=5 THEN [Business Area]+"0"+[Doc Nbr]
ELSEIF [Length]=4 THEN [Business Area]+"00"+[Doc Nbr]
ELSEIF [Length]=3 THEN [Business Area]+"000"+[Doc Nbr]
ELSEIF [Length]=2 THEN [Business Area]+"0000"+[Doc Nbr]
ELSEIF [Length]=1 THEN [Business Area]+"00000"+[Doc Nbr]
ELSE Null()
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
Thank you.
Lyn
Solved! Go to Solution.
Hi Lyn ( @nylasor_17 )
By the looks of it, you don't need all the extra EndIFs at the end of your statement, so the below should be enough
IF [Length]=6 THEN [Business Area]+[Doc Nbr]
ELSEIF [Length]=5 THEN [Business Area]+"0"+[Doc Nbr]
ELSEIF [Length]=4 THEN [Business Area]+"00"+[Doc Nbr]
ELSEIF [Length]=3 THEN [Business Area]+"000"+[Doc Nbr]
ELSEIF [Length]=2 THEN [Business Area]+"0000"+[Doc Nbr]
ELSEIF [Length]=1 THEN [Business Area]+"00000"+[Doc Nbr]
ELSE Null()
ENDIF
If the issue remains, can you click on the metadata tab of your results pane and post a screenshot of the data type for the fields
[Length]
[Business Area]
[Doc Nbr]
Cheers,
Angelos
Hi Angelos,
I tried that only 1 ENDIF however there still an error. attached the screenshot of data type.
Hope you can help me.
Thank you
Lyn
Hi,
You have two options:
1) Length is V_Wstring so use [Length]='6' instead of [Length]=6
2) Define Length as Int16 and don't change your formula.
Thank you,
Luis
@nylasor_17 so the issue is that the field [Length] is a V_WString so you are trying to compare a string to a numeric value.
You can change the data type for the field [Length] to an INT64 and that should make the error go away.
Let me know if that worked for you please.
Cheers,
Angelos
hey @nylasor_17
I believe you'll want the following:
I also have below this, a switch statement, that does the exact same thing. Switch statements are generally the 'correct' way to do this type of if-statement, as they are marginally faster (and I think look cleaner). May be useful for you!
I've attached a workflow with it too.
Thank you Angelos
The formula is accepted. 😉😊