Discuss a wide range of topics! Questions about the Alteryx Platform should be directed to the appropriate Product discussion forum.

if statement with datetimeadd invalid type in operator

5 - Atom

Hello! I am trying to create this formula:


IF [YEAR] = "2019" THEN [DATE] + 365 ELSE [DATE] ENDIF


but it gives me malformed if statement or invalid type in operator error. Please help?

16 - Nebula
16 - Nebula

To add days to a date (or datetime) you need to use the DateTimeAdd function.


Additionally if [YEAR] is a number type (not a text field) then you need to not have the quotes as it will complain that types don't match


Something like:


IF [YEAR] = 2019 THEN DateTimeAdd([DATE], 365, "days") ELSE [DATE] ENDIF


should get what you need