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

Complex Row Time Difference

Hi Team. Is there a way to reproduce this in Powerbi.?

powerbi2.JPG

 

This is the table I have to, in theory, I would like to subtract the time or duration between 2:36 PM and 2:50PM the same way I did in my excel file. Any idea on how to achieve this?

Lost time.JPG

 

Thanks

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

Try this calculated column formula

=data[start time]-calculate(max(data[end time]),filter(data,data[start time]<earlier(data[start time])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-henryk-mstf
Community Support
Community Support

Hi @carlosdajer ,

 

According to the table you provided, your purpose is to get the difference between the Time Out column and the next time value in Time IN column through power Bi. I did the following test: by defining two variables, var curindex is used to obtain the index value, var nextstratime is used to obtain the date value of the next row of the current row in the Start Time column, and finally the difference value is obtained by using the DATEDIFF function.

v-henryk-mstf_0-1608773057755.png

 

Here is the sample pbix file.

 

Best Regards,
Henry

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I cant download the file, can you grant me access?

There @carlosdajer ,

I am sorry for my behavior.

Here is the right sample pbix file.

Best Regards,
Henry

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Can you do the same but with unsorted rows? I have the index but the timestamp is not in order. How can we achieve the same result?

Hi @carlosdajer

 

The created Standard answer measure calculates the result of the current row. When the timestamp changes, the value will also change. And the order of calculation will be based on index column, you can observe "var st". In addition, you can refer to the Duration measure, even if it is an unsorted row, it will still be calculated based on the index.

v-henryk-mstf_0-1608881598751.png

 

You can check the pbix file.

 

Best regards,

Henry

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for the help. Appreciate the time. m not getting the same results. Im sharing the code + the table 

.Duration =
var curindex = MAX('OMNI Hours Report'[Index])
var nextstartime = CALCULATE(MIN('OMNI Hours Report'[Start Time]),FILTER(ALL('OMNI Hours Report'),'OMNI Hours Report'[Index]>=curindex+1))
return DATEDIFF(MAX('OMNI Hours Report'[End Time]),nextstartime,SECOND)

Lost time.JPG
Greg_Deckler
Super User
Super User

@carlosdajer See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

That did not work. Sorry

 

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.