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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Power Query - How to Calculate Time Difference with Previous Row & Adjacent Column?

 
2 ACCEPTED SOLUTIONS
speedramps
Super User
Super User

Thanks for your clear question and example data. I wish all members did that!

 

There are a few methods you can use, but try this one ....


Create a measure tp get the previous stop time

 

Previous stop time =
VAR mystart = SELECTEDVALUE(Microchips[Start time])
RETURN
CALCULATE(
    MAX(Microchips[Stop time]),
    ALL(),
    Microchips[Stop time] <= mystart
    )
 
Then create a measure to get the idle tile between the batches.
You can do this in any unit of measure, but I have used minutes in this example
 
Minutes idle =
DATEDIFF([Previous stop time],SELECTEDVALUE(Microchips[Start time]),MINUTE)


speedramps_0-1697810216327.png

Thanks for reaching out for help.

I put in a lot of effort to help you, now please quickly help me by giving kudos.

Remember we are unpaid volunteers and here to coach you with Power BI and DAX skills and techniques, not do the users job for them. So please click the thumbs up and accept as solution button. 

If you give someone a fish then you only give them one meal, but if you teach them how to fish then they can feed themselves and teach others for a lifetime.  I prefer to teach members on this forum techniques rather give full solutions and do their job. You can then adapt the technique for your solution, learn some DAX skills for next time and soon become a Power BI Super User like me. 

One question per ticket please. If you need to extend your request then please raise a new ticket.

You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you ! 


If you quote @speedramos in yout tickers then I will then received an automatic notification, and will be delighted to help you if you click the humbs up and accept as solution button. Thank you.

View solution in original post

mickey64
Super User
Super User

For your reference.

 

Step 1: I load the data with Power Query Editor twice as 'DATA_01' and 'DATA_02'.

    mickey64_0-1697810717090.png

    mickey64_1-1697810758796.png

 

Step 2: I add 'Index+1' column to 'DATA_02'.

    mickey64_2-1697810858597.png

    mickey64_3-1697810954843.png

 

Step 3: I merge 'DATA_01' query and 'DATA_02' query with 'Index' and 'Index+1'.

    mickey64_5-1697811138776.png

    mickey64_4-1697811025306.png

 

Step 4: I expand 'DATA_02'.

    mickey64_6-1697811217082.png

 

Step 5: I add 'Elapsed Time in Minutes' column to 'DATA_01' in Power BI Desktop.

    Elapsed Time in Minutes = DATEDIFF([DATA_02.STOP TIME],[START TIME],MINUTE)

 

    mickey64_7-1697811347372.png

 

View solution in original post

2 REPLIES 2
mickey64
Super User
Super User

For your reference.

 

Step 1: I load the data with Power Query Editor twice as 'DATA_01' and 'DATA_02'.

    mickey64_0-1697810717090.png

    mickey64_1-1697810758796.png

 

Step 2: I add 'Index+1' column to 'DATA_02'.

    mickey64_2-1697810858597.png

    mickey64_3-1697810954843.png

 

Step 3: I merge 'DATA_01' query and 'DATA_02' query with 'Index' and 'Index+1'.

    mickey64_5-1697811138776.png

    mickey64_4-1697811025306.png

 

Step 4: I expand 'DATA_02'.

    mickey64_6-1697811217082.png

 

Step 5: I add 'Elapsed Time in Minutes' column to 'DATA_01' in Power BI Desktop.

    Elapsed Time in Minutes = DATEDIFF([DATA_02.STOP TIME],[START TIME],MINUTE)

 

    mickey64_7-1697811347372.png

 

speedramps
Super User
Super User

Thanks for your clear question and example data. I wish all members did that!

 

There are a few methods you can use, but try this one ....


Create a measure tp get the previous stop time

 

Previous stop time =
VAR mystart = SELECTEDVALUE(Microchips[Start time])
RETURN
CALCULATE(
    MAX(Microchips[Stop time]),
    ALL(),
    Microchips[Stop time] <= mystart
    )
 
Then create a measure to get the idle tile between the batches.
You can do this in any unit of measure, but I have used minutes in this example
 
Minutes idle =
DATEDIFF([Previous stop time],SELECTEDVALUE(Microchips[Start time]),MINUTE)


speedramps_0-1697810216327.png

Thanks for reaching out for help.

I put in a lot of effort to help you, now please quickly help me by giving kudos.

Remember we are unpaid volunteers and here to coach you with Power BI and DAX skills and techniques, not do the users job for them. So please click the thumbs up and accept as solution button. 

If you give someone a fish then you only give them one meal, but if you teach them how to fish then they can feed themselves and teach others for a lifetime.  I prefer to teach members on this forum techniques rather give full solutions and do their job. You can then adapt the technique for your solution, learn some DAX skills for next time and soon become a Power BI Super User like me. 

One question per ticket please. If you need to extend your request then please raise a new ticket.

You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you ! 


If you quote @speedramos in yout tickers then I will then received an automatic notification, and will be delighted to help you if you click the humbs up and accept as solution button. Thank you.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.