Free Trial

Alteryx Designer Desktop Discussions

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

Problem with IF statement and date

Julie_Clarke
6 - Meteoroid

Hi,

 

I'm new to Alteryx and am trying to convert a formula I have working in Excel for use in Alteryx:

 

IF([Start Date]> DateTimeToday(),
[Finish Date]-[Start Date],
IF([Finish Date]-DateTimeToday()<=0,7,[Finish Date]-DateTimeToday()))/7

 

But I'm getting an error of Error: Formula (21): Parse Error at char(32): Malformed If Statement (Expression #1)

 

My original code was:  

=IF(Start Date>TODAY(),Finish Date-Start Date,IF(Finish Date-TODAY()<=0,7,Finish Date-TODAY()))/7

 

Any suggestions or solutions would be much appreciated.

8 REPLIES 8
ShankerV
17 - Castor

Hi @Julie_Clarke 

 

Try this

 

IF [Start Date]> DateTimeToday()

THEN [Finish Date]-[Start Date]

ELSEIF [Finish Date]-DateTimeToday()<=0

THEN 7

ELSE [Finish Date]-DateTimeToday()/7

ENDIF

 

binuacs
21 - Polaris

@Julie_Clarke Use DateTimeDiff function for taking the date difference

 

 

IIF([Start Date] > DateTimeToday(),DateTimeDiff([Finish Date],[Start Date],'day'),
IIF(DateTimeDiff([Finish Date],DateTimeToday(),'day')<=0,7,DateTimeDiff([Finish Date],DateTimeToday(),'day')))/7

 

Julie_Clarke
6 - Meteoroid

Of course - thank you.

Julie_Clarke
6 - Meteoroid

Hi 

 

Thanks for this, but this generates an error 

 

Error: Formula (21): Parse Error at char(147): Formula: tried to apply numeric operator to string value (Expression #1) ??

 

My dates are in date format.

binuacs
21 - Polaris

@Julie_Clarke It is difficult to say what might be the issue without seeing your input data. I am attaching a sample workflow that uses the same formula on two date fields. Can you compare with your workflow?

 

Julie_Clarke
6 - Meteoroid

Hi,

 

Thanks for your interest / help.

 

Attached is some sample data with the core date fields.  As you'll see from this ,my duration calculation (Column p) gives me decimals rather than integers.

 

Using the calculation suggested I only get full numbers - I'm obviously missing something ??🙄

binuacs
21 - Polaris

@Julie_Clarke Changing the data type in the formula tool to an integer will solve the decimal issue

 

binuacs_0-1675977781799.png

 

Julie_Clarke
6 - Meteoroid

Hi, 

 

I did that initially and it didn't seem to work, hence my email but have now tried again with success - thank you for confirming the approach.  

Labels
Top Solution Authors