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
logicscience2
Regular Visitor

calculate duration between date-time of consecutie date-time rows

I have data of this format :

logicscience2_0-1711906549015.png

 

during import the data is sorted by date-time column then the Index column is added. So regardless how the table is sorted after import, the index can maintain a reference to sequential date-time values.

 

I am trying to add the duration-between calculated column which will calculate the difference between two rows based on the index order so in the picture above the first row would be blank or error, the second row would be 235 (minutes), the third would be  52 (minutes) and so on. These values would stay correctly calculated regardless of the ordering on the table.

 

 

1 ACCEPTED SOLUTION
logicscience2
Regular Visitor

This solution seems to work:

 

DurationBetween =
VAR CurrentDateTime = df[date-time]
VAR NextDateTime =
CALCULATE(
MIN(df[date-time]),
FILTER(
df,
df[date-time] > CurrentDateTime
)
)
RETURN
IF(
ISBLANK(NextDateTime),
BLANK(),
(NextDateTime - CurrentDateTime)*24*60
)

View solution in original post

1 REPLY 1
logicscience2
Regular Visitor

This solution seems to work:

 

DurationBetween =
VAR CurrentDateTime = df[date-time]
VAR NextDateTime =
CALCULATE(
MIN(df[date-time]),
FILTER(
df,
df[date-time] > CurrentDateTime
)
)
RETURN
IF(
ISBLANK(NextDateTime),
BLANK(),
(NextDateTime - CurrentDateTime)*24*60
)

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!

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.