We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Malformed If Statement but not showing where the error is

jpet03
6 - Meteoroid

I have 3 specific numbers that should start with 0, but the excel removes the leading 0. For these 3 codes, I want to add the 0 back in and am using a quick if statement to do so. Even though it does not show that there is an error in the code, I am getting a parse error / malformed if statement.

 

Any ideas on resolution would be helpful.

 

Thanks.

 
 

 

4 REPLIES 4
alexnajm
18 - Pollux
18 - Pollux

At a quick glance, try ELSEIF instead of ELSE IF

alexnajm
18 - Pollux
18 - Pollux

But also why are you using the ToString functions? You are already forcing the numbers to be strings by putting single quote around them

alexnajm
18 - Pollux
18 - Pollux

Also reading this function further, what is your end goal? It's a bit confusing

DataNath
17 - Castor
17 - Castor

Hey @jpet03, how do you get on with this? Just a simplified version of what you're mentioning. Before vs after:

 

 

1.png2.png

 

IF [Code] IN ('088','133','147')
THEN '0'+[Code]
ELSE [Code]
ENDIF

 

Some things of note in the original:

 

1) ToString() should wrap the field, i.e. it should be IF ToString([Code]) = '088'...

2) As your field is already a string, there's no need for ToString(), you could just use IF [Code] = '088'...

3) The then statements don't need <field> = again, you just need to state the result and nothing else i.e. ... THEN '0088'...

4) I don't actually think it makes a difference as I'm sure I've seen workflows working with both, but it should be ELSEIF i.e. one word rather than two

 

Some more helpers and explainers can be found in a blog I wrote a little while ago here: https://community.alteryx.com/t5/Engine-Works/Troubleshooting-Common-Formula-Expression-Errors/ba-p/...

 

Hope this helps!

Labels
Top Solution Authors