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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.