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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

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

 
2 ACCEPTED SOLUTIONS
speedramps
Community Champion
Community Champion

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
Community Champion
Community Champion

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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