Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Nested If then Else issues

bcastle88
6 - Meteoroid

I'm a new Alteryx user and i'm creating my 1st work flow. I'm using dates and need to buckets those dates into Fiscal Years. I currently do this via excel or in Tableau but would love to add this as a formula in my work flow. I have verified my dates are in the correct format (yyyy-mm-dd) so that isnt an issue. I'm using the below formula and I get get  the following error "Parse Error at char(216): Malformed If Statement (expression # 5)". Do i need to convert the dates? They initally come over with time stamps but i use the Configuration tool to remove those. Any help would be greatly appreciated.

 

IF [LASTDATE] < 2017-06-30 AND [LASTDATE] > 2016-06-30 THEN "FY17"

ELSEIF
IF [LASTDATE] < 2016-06-30 AND [LASTDATE] > 2015-06-30 THEN "FY16"

ELSEIF
IF [LASTDATE] < 2015-06-30 AND [LASTDATE] > 2014-06-30 THEN "FY15"

ENDIF

 

If there is a better way to do this using another tool i'm open to that as well.

 

3 REPLIES 3
michael_treadwell
ACE Emeritus
ACE Emeritus

Try quoting your dates and removing the IFs after the ELSEIFs. Also, all ELSEIF statements should end with ELSE THEN ENDIF.

 

The conditional synatx for Alteryx is IF c THEN t ELSEIF c2 THEN t2 ELSE f ENDIF

 

Try this:

 

IF [LASTDATE] < '2017-06-30' AND [LASTDATE] > '2016-06-30' THEN "FY17"

ELSEIF [LASTDATE] < '2016-06-30' AND [LASTDATE] > '2015-06-30' THEN "FY16"

ELSE [LASTDATE] < '2015-06-30' AND [LASTDATE] > '2014-06-30' THEN "FY15"

ENDIF

tom_montpool
12 - Quasar

Based on your example, I think just some small changes should make it work for you:

 

IF [LASTDATE] < 2017-06-30 AND [LASTDATE] > 2016-06-30 THEN "FY17"

ELSEIF
IF [LASTDATE] < 2016-06-30 AND [LASTDATE] > 2015-06-30 THEN "FY16"

ELSEIF
IF [LASTDATE] < 2015-06-30 AND [LASTDATE] > 2014-06-30 THEN "FY15"

ELSE "ERROR"

ENDIF

 

You might also want to change some of the ">" or "<" to ">=" or "<=" because right now, any of the specific dates you've listed (e.g. 2016-06-30) won't be assigned to a fiscal year.

bcastle88
6 - Meteoroid

Hey Guys,

Thanks for the quick response. It actually took a combination of both of your posts.

 

IF [LASTDATE] <= '2017-06-30' AND [LASTDATE] > '2016-06-30' THEN "FY17"
ELSEIF [LASTDATE] <= '2016-06-30' AND [LASTDATE] > '2015-06-30' THEN "FY16"
ELSEIF [LASTDATE] <= '2015-06-30' AND [LASTDATE] > '2014-06-30' THEN "FY15"
ELSE "ERROR"
ENDIF

 

And I had to convert the output field from numeric to V String.

Thanks again.

B

Labels