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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
bdehning
Post Prodigy
Post Prodigy

DATEDDIFF Help

I am using the following to determine number of years between two dates in DAX.   I don't think my results are correct.  Is the measure, correct?   Both fields are Date Fields. 

  

YearDurationMeasure = DATEDIFF([Claimant Hire Date],[Loss Date],YEAR)
2 ACCEPTED SOLUTIONS
Ritaf1983
Super User
Super User

Hi @bdehning 

It depends on what you are trying to do.

The function in the way you wrote it can work as a calculated column because it requires scalar values and returns the number of calendar years that were between the two values. In other words, if your two dates are within the same calendar year, for example 2023, you will get 0, and if one date is 2022 and the other 2023, you will get 1 even if it was only one month between the two dates.

If you are interested in accurately returning the number of years, including fractions, you can use the function:

Years_with_parts = ([Loss Date]-[Claimant Hire Date])/365
If you need a measure and not a calculated column you need to calculate the function on some aggregated form like :

datediff_measure = DATEDIFF(max('Table'[Claimant Hire Date]),max('Table'[Loss Date]),YEAR)
more information about Datediff is here:https://www.youtube.com/watch?v=_z1XSR7fRYA
Pbix with examples is attached
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

Hi @bdehning 
Again, it depends on the needed logic.
If you need calendar months then :

Months = DATEDIFF([Claimant Hire Date],[Loss Date],MONTH)
If you need the differences including parts  :
months with parts = ([Loss Date]-[Claimant Hire Date])/30
If the second version should be a measure :
months_with parts_measure = SUMX('Table',DATEDIFF([Claimant Hire Date],'Table'[Loss Date],DAY)/30)
 
The updated pbix is attached
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
 
Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

4 REPLIES 4
Ritaf1983
Super User
Super User

Hi @bdehning 

It depends on what you are trying to do.

The function in the way you wrote it can work as a calculated column because it requires scalar values and returns the number of calendar years that were between the two values. In other words, if your two dates are within the same calendar year, for example 2023, you will get 0, and if one date is 2022 and the other 2023, you will get 1 even if it was only one month between the two dates.

If you are interested in accurately returning the number of years, including fractions, you can use the function:

Years_with_parts = ([Loss Date]-[Claimant Hire Date])/365
If you need a measure and not a calculated column you need to calculate the function on some aggregated form like :

datediff_measure = DATEDIFF(max('Table'[Claimant Hire Date]),max('Table'[Loss Date]),YEAR)
more information about Datediff is here:https://www.youtube.com/watch?v=_z1XSR7fRYA
Pbix with examples is attached
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

What would be needed to add to your datedif file to show number of months from Claimant Hire Date and Loss Date?

Hi @bdehning 
Again, it depends on the needed logic.
If you need calendar months then :

Months = DATEDIFF([Claimant Hire Date],[Loss Date],MONTH)
If you need the differences including parts  :
months with parts = ([Loss Date]-[Claimant Hire Date])/30
If the second version should be a measure :
months_with parts_measure = SUMX('Table',DATEDIFF([Claimant Hire Date],'Table'[Loss Date],DAY)/30)
 
The updated pbix is attached
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
 
Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

It worked fine and would months with parts be the most accurate measure to use to use number of months after claimant hire date.  I noticed Pandora shows 25 months for Sum of Months and 26.13 for Sum of months with parts.  

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.