Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
ihartdata
Microsoft Employee
Microsoft Employee

DATEDIFF with blanks and wonky dates - need help!

Hi,

 

I am trying to create a calculated column to provide the number of days between an inbound request and an outbound invitation. All of the data needed is now contained in one table. Unfortunately some of the dates are blank and other rows have the outbound invitation (end date) before the inbound request (start date) and that is throwing errors. I solved for the Blank dates and I solved for the End Date before the Start Date, and now I am getting an error that says the Start Date can't be greater than the end date. Which is confusing because I think it means the same thing: End Date<Start Date = Start Date>End Date??

 

Here is sample data:

Sample Data.PNG

 

Here is the DAX I have wrote so far:

Days to Enroll = IF(OR(ISBLANK('Table'[Start Date]),ISBLANK('Table'[End Date])),3,(IF(OR('Table'[End Date]<'Table'[Start Date],'Table'[Start Date]>'Table'[End Date]),-1*DATEDIFF('Table'[Start Date],'Table'[End Date],DAY),DATEDIFF('Table'[Start Date],'Table'[End Date],DAY))))

 

Here is the Error I am receiving: "In DATEDIFF function, the start date cannot be greater than the end date"

 

Help me! thank you. 🙂

1 ACCEPTED SOLUTION
thomasronn
Resolver I
Resolver I

Swap start and end date in DATEDIFF() when Start Date i greather than End Date.

Change this part 

...-1*DATEDIFF('Table'[Start Date],'Table'[End Date],DAY)...

to

...-1*DATEDIFF('Table'[End Date],'Table'[Start Date],DAY)...

 

and yes, End Date<Start Date = Start Date>End Date. So you don't need to check both

View solution in original post

3 REPLIES 3
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi there

 

The DATEDIFF function will throw and error if it things the first of the two parameters is larger than the second parameter,

 

Are you just after the number of days between each date?

 

If so, covert the dates to INTand then subtract the values.  This will give negative numbers for inverse dates (but no error)

 

CalcColumn = INT('Table'[End Date] - 'Table'[Start Date])

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

thomasronn
Resolver I
Resolver I

Swap start and end date in DATEDIFF() when Start Date i greather than End Date.

Change this part 

...-1*DATEDIFF('Table'[Start Date],'Table'[End Date],DAY)...

to

...-1*DATEDIFF('Table'[End Date],'Table'[Start Date],DAY)...

 

and yes, End Date<Start Date = Start Date>End Date. So you don't need to check both

Thomas!!! That worked. Thank you, thank you, thank you. I have been racking my brains for way too long. Super appreciated! Have a lovely weekend.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.