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.
Solved! Go to Solution.
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
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"
ELSEIFIF [LASTDATE] < 2016-06-30 AND [LASTDATE] > 2015-06-30 THEN "FY16"
ELSEIFIF [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.
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