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
niel_orvyn1
Helper III
Helper III

Calculating the value of time difference between rows

Hi there,

New to power Bi and trying to move away from excel

I'm trying to calculate the time difference between two rows. 

 

Below table "Time Diff" is the difference between the the previous row and the next row in  "Time" column. 

 
 

(Context: Trying to determine the total time in minutes,seconds between events in order to apply a threshold filter) 

EventCam Event time stampDateDateMonth

Time

 

Time diffOver Threshold
lens_dirtycam_465156463377101/08/2019 04:2901/08/2019August05:34:3105:34:31TRUE
lens_dirtycam_465156463767101/08/2019 05:3401/08/2019August06:34:3101:00:00TRUE

 

Let me know if you are able to assist and if my question is clear, else I can upload the excel sheet. 

 

Thanx

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

you need to create index column and then you have to use lookupfunction as below

Column=lookupvalue(table[time],table[index],table[index]+1,table[event],table[event])

 

This will return time of next row for current row for same event.

 

Then simple use datediff as below

difference column=datediff(table[time],Column,Sec)

incase you want measure

difference measure=datediff(max(table[time]),max(Column),Sec)

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

 

View solution in original post

Anonymous
Not applicable

update formula as below

 

prevRlookup=

var init=same formula last one

return

if(init=blank(),"expected value",init)

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

you need to create index column and then you have to use lookupfunction as below

Column=lookupvalue(table[time],table[index],table[index]+1,table[event],table[event])

 

This will return time of next row for current row for same event.

 

Then simple use datediff as below

difference column=datediff(table[time],Column,Sec)

incase you want measure

difference measure=datediff(max(table[time]),max(Column),Sec)

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

 

Much appreciated! Worked perfectly. 

I've run into the following problem:

 

The index+1 on the 1st timestamp of the month does not return a value. (Highlighted in yellow)

 

So when I subract the "PrevLookup" from the "timestamp" I get a value but would like it to be zero in order to get the sum of the "Diff" colum. However, the 63161281 gives me an incorrect figure. 

 

I can remove it with a filter but applying more measure down the line I run into problems. 

 

Is there something I can add to the line or is there a workaround? 

 

Best

 

 

Annotation 2020-03-13 144242.png

Anonymous
Not applicable

update formula as below

 

prevRlookup=

var init=same formula last one

return

if(init=blank(),"expected value",init)

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

 

it works but with "expected value" being text, cannot convert it to date or number. So timedifference between to two date columns wont work. 

 

prevRlookup=

var init=same formula last one

return

if(init=blank(),"expected value",init)

 

Appreciate your help and sorry to keep asking.

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.

Top Solution Authors