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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.

Top Solution Authors