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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
UK_User123456
Resolver I
Resolver I

Calculating difference between two dates

Hi All,

 

I have come across a snap when trying to calculate the difference between two dates.

 

As in my example, I tried to calculate the difference between two dates using the "datediff" function for both monthly and days but the result seem way off and I dont know why.

 

Monthly    
Last Gift PYLast Gift DateDate Difference Correct result
31/03/201917/06/201968 3
04/03/201903/06/2019113 3
01/03/201903/06/201915 3
02/07/201822/05/2019113 11
     
Days    
Last Gift PYLast Gift DateDate Difference Correct result
31/03/201917/06/20192071 78
04/03/201903/06/20193420 91
01/03/201903/06/20193458 94
02/07/201822/05/20193431 324

 

I have tried the following to get the number of days:

Date Difference Last Gift (By Day) = DATEDIFF([Last Gift PY],'Constituent Last Gift Data'[Last Gift Date],DAY )
 
and the following for month:
Date Difference Last Gift (By Day) = DATEDIFF([Last Gift PY],'Constituent Last Gift Data'[Last Gift Date],Month )
 

 

Date difference is a calculated column in my table.

 

TIA

1 ACCEPTED SOLUTION

Date 1 is format type Date/Time and the Date 2 is format type Date, so they should be the same, but I have changed both the date(s) to Date format and still get the same issue.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

To Calculating the difference between two dates  in a decimal number of months I use: 

 

Date.Month([EndDate])-Date.Month([StarDate]) + ((Date.Day([EndDate])/Date.DaysInMonth([EndDate])) +(Duration.TotalDays(Date.EndOfMonth([StarDate])-[StarDate])/Date.DaysInMonth([StarDate]))-1))

 

 

Anonymous
Not applicable

Did you make sure their formats are the same (dd/MM/yyyy)?

There could be a format mismatch.

 

BR,

Abel

Date 1 is format type Date/Time and the Date 2 is format type Date, so they should be the same, but I have changed both the date(s) to Date format and still get the same issue.

@AnonymousThanks for your fast response, I did originally try it as a measure, but it didnt work. And after researching it on google, it said that you should put it in as a calculated column not measure.

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors