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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.