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

Alteryx Designer Desktop Discussions

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

Malformed If Statement

lindsayhupp
8 - Asteroid

Hi everyone!  I'm relatively new to Alyterx and trying to comprise an IF statement that also nests with an AND statement.  I got the formula to work in Excel, but am having trouble converting it to Alteryx.  I've read some information about IF ELSE formulas in Alteryx, but I did a separate IF statement (without the AND) and it worked very similarly to how it works in Excel so I was trying to do the same for this.  Any help would be appreciated!

 

iif([Year]=1,DateTimeDiff([End Date1],[Start Date2],"days"),iif([Year]>1 AND [End Date1]>[End Date2],[End Date2]-[Start Date1],[End Date1]-[Start Date1])

3 REPLIES 3
BrandonB
Alteryx
Alteryx

Maybe give this a try?

 

IF [Year] = 1

THEN DateTimeDiff([End Date1],[Start Date2],"days")

ELSEIF [Year]>1 AND [End Date1]>[End Date2]

THEN [End Date2]-[Start Date1]

ELSE [End Date1]-[Start Date1]

ENDIF

 

BenMoss
ACE Emeritus
ACE Emeritus

Hi! Brandon’s solution might work and I think with written syntax rather than the syntax you use it’s a bit easier to find where the problems are, however in your case I think you are missing a closing bracket at the end. You have too IIF statements and therefor you need to close both.

 

iif([Year]=1,DateTimeDiff([End Date1],[Start Date2],"days"),iif([Year]>1 AND [End Date1]>[End Date2],[End Date2]-[Start Date1],[End Date1]-[Start Date1]))

 

Further to this I don’t think Alteryx likes you just doing DATE-DATE and you should use the datetimediff function in all cases.

 

Ben

lindsayhupp
8 - Asteroid

Thanks for the responses!  I was able to get it to work!

Labels
Top Solution Authors