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

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

Reply
Anonymous
Not applicable

Calculate difference in time between dates in same column

Hi all,

 

I have the following column, and I wish to calculate the difference between each row - ie the length of time between Row 2 (20/08/18) and Row 1 (18/01/2017).

 

custerdome_0-1676659370681.png

 

 

Any ideas on how to effectively do this?

 

Thanks!

 

4 REPLIES 4
tamerj1
Super User
Super User

Hi @Anonymous 

Please try

Days Difference =
VAR SelectedDates =
ALLSELECTED ( 'Table'[Date] )
RETURN
SUMX (
VALUES ( 'Table'[Date] ),
VAR CurrentDate = 'Table'[Date]
VAR FilteredDates =
FILTER ( SelectedDates, 'Table'[Date] < CurrentDate )
VAR PreviousDate =
MAXX ( FilteredDates, 'Table'[Date] )
RETURN
IF ( PreviousDate <> BLANK (), INT ( CurrentDate - PreviousDate ) )
)

Anonymous
Not applicable

My apologies, the dates should have been in ascending order as in the screenshot below now. There are other rows that I'd rather not show if possible for privacy reasons (ie work related), but the dates should be the column by which the table is sorted.

 

And to answer your other question, a calculated column would be the ideal scenario.

 

Thank you for your help so far!

 

custerdome_0-1676723506714.png

 

FreemanZ
Super User
Super User

hi @Anonymous 

do you have other columns?

OwenAuger
Super User
Super User

Hi @Anonymous 

The OFFSET function would work well here.

 

To come up with the exact DAX expression, we would need to clarify:

  • What determines the sort order? I can see the dates in your image are not in ascending/descending order. Is there another column partitioning or defining the sort order?
  • Do you want a measure (which would respond to filters) or a calculated column?
    In the case of a measure, we would need to clearly define which dates are included, for example it could be all dates visible in the filter context, or all dates for which certain measure(s) are nonblank.

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.