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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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