Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

Malformed IF statement when I add ENDIF

Dcaston
5 - Atom

 

Can someone help me understand why when I add the ENDIF to the end of my statement, everything following the 2 then 'Plan 2 activation date' "etc... become unhighlighted. I then see the parse error at char(153): Malformed If statement. Oddly enough, when I remove the ENDIF the entire conditional function is highlighted, but of course, it can't perform if it doesn't have an ENDIF for an IF ELSE function.

 

I have tried using both the formula & filter tool to perform this.

 

IF [Red_flag] = 'Y' then 'Red_flag Activation'
ELSEIF [AC_Min] = 1 then 'Plan 1 Activation Date'
elseif [AC_Min] = 2 then 'Plan 2 Activation Date'
ELSE ToString([PLAN_id]) ENDIF

 

4 REPLIES 4
DataNath
17 - Castor
17 - Castor

Hey @Dcaston, the syntax of your statement looks fine so it’s likely that the data type of your [AC_Min] field is a string, but you’re treating it as a number I.e. you haven’t wrapped it in quotes. You can either change the data type of the field to numeric using a select tool or just place quotation marks around the number eg [AC_Min] = ‘2’.

Felipe_Ribeir0
16 - Nebula

Hi @Dcaston 

 

The AC_Min field on your workflow is being interpreted as a string field, so or you put the numbers between quotes on your formula ([AC_Min] = '1'), or you transform the field into a numeric field with the select tool.

 

Felipe_Ribeir0_0-1668975181163.png

 

apathetichell
19 - Altair

the error is occurring at 153 - if this was related to AC_MIN being a string - the error would be at 114. Your statement is running fine on 21.4. I'd check for the following:

1) Are all of your fields separated by a space from the boolean terms/operators?

2) What happens if you swap elseif to ELSEIF

 

Basically try cutting and pasting into formula tool what you posted here.

Adrian_T
Alteryx Alumni (Retired)

Hey @Dcaston,

 

All the replies from @DataNath@Felipe_Ribeir0 and @apathetichell should help you debug your nested IF formula just fine. 😊 I just thought to also share a great alternative formula that would help you simplify complex nested IF formulas in future.

 

This will definitely be dependent on your own preference, but I personally like using the IIF conditional statement instead. You can nest another IIF statement as a replacement for y, and just like that you remove the need, and more importantly any possible typos for "THEN", "ELSE", "ENDIF" etc. 😎

 

IIF(bool, x, y): Returns x if bool is true, else returns y.

 

Labels