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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon โ€“ Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save โ‚ฌ200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors