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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Peter_2020
Helper III
Helper III

Time difference between specific rows

Hello all, 

I would like to ask for help with calculation of time difference between specific rows in one table. I have this kind of data:

 

DATE/TIMERCKEY
7-10-20 6:00 AM110101
7-10-20 6:05 AM110201
7-10-20 6:10 AM110301
7-10-20 6:20 AM110104
7-10-20 6:25 AM110205
7-10-20 6:30 AM110306
7-10-20 6:30 AM110103
7-10-20 6:40 AM110203
7-10-20 6:50 AM110303

 

And what I want to do is to calculate time difference between rows with key - 04, 05, 06 and next row but with the same RC number. So my expected output is:

 

DATE/TIMERCKEYTIME DIFFERENCE
7-10-20 6:00 AM110101 
7-10-20 6:05 AM110201 
7-10-20 6:10 AM110301 
7-10-20 6:20 AM1101040:10
7-10-20 6:25 AM1102050:15
7-10-20 6:30 AM1103060:20
7-10-20 6:30 AM110103 
7-10-20 6:40 AM110203 
7-10-20 6:50 AM110303 

 

* colors marked which rows are calculated

 

Thank you for your help in advance.

P

1 ACCEPTED SOLUTION
Peter_2020
Helper III
Helper III

Finally I found solution. For those whom it can help:

 

Time Difference Measure =
VAR NextRow =
CALCULATE (
MIN ( Table[DATE/TIME]), FILTER ( ALLEXCEPT ( Table , Table[RC] ), Table[DATE/TIME] > SELECTEDVALUE ( Table[DATE/TIME])))
 
RETURN
IF (
SELECTEDVALUE ( Table[Bit] ) = 1,
DATEDIFF ( SELECTEDVALUE ( Table[DATE/TIME] ), NextRow, SECOND ))
 
BIT is measure which returns 1 for KEY - 04,05,06.

 

View solution in original post

3 REPLIES 3
Peter_2020
Helper III
Helper III

Finally I found solution. For those whom it can help:

 

Time Difference Measure =
VAR NextRow =
CALCULATE (
MIN ( Table[DATE/TIME]), FILTER ( ALLEXCEPT ( Table , Table[RC] ), Table[DATE/TIME] > SELECTEDVALUE ( Table[DATE/TIME])))
 
RETURN
IF (
SELECTEDVALUE ( Table[Bit] ) = 1,
DATEDIFF ( SELECTEDVALUE ( Table[DATE/TIME] ), NextRow, SECOND ))
 
BIT is measure which returns 1 for KEY - 04,05,06.

 

amitchandak
Super User
Super User

@Peter_2020 , Try a new column like

if([Key] in {"04","05","06"}, [Date/time], Maxx(filter(table,[RC] =earlier([RC]) && [Date/time] <earlier([Date/time])),[Date/time]), blank())

 

But I doubt you are doing diff with the same RC number

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak  Thanks for your help but it doesn´t work. I forgot to mention that I am using DirectQuery mode.

Helpful resources

Announcements
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.