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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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