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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
xsaldana
Regular Visitor

How do I create a column that returns the change in time for two times in the same column?

I am attempting to create a column in Power BI that will return the difference in time. The table below is an example of how my data is currently formatted. For instance, the first value in the "Time Difference" will be 0 and the second will be 4 minutes (2:05:00 AM - 2:01:00 AM) and the second will be 1 minute (2:06:00 AM - 2:05:00 AM). Any suggestions on how to tackle this?

xsaldana_1-1649277237023.png

 

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @xsaldana ,

 

Here a possible solution 🙂

 

tomfox_0-1649278139279.png

 

 

Here the DAX:

Time Difference = 
DATEDIFF (
    CALCULATE (
        MAX ( 'Table'[Time] ),
        FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
    ),
    'Table'[Time],
    MINUTE
)

 

 

Does this solve your issue? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

3 REPLIES 3
tackytechtom
Super User
Super User

Hi @xsaldana ,

 

Here a possible solution 🙂

 

tomfox_0-1649278139279.png

 

 

Here the DAX:

Time Difference = 
DATEDIFF (
    CALCULATE (
        MAX ( 'Table'[Time] ),
        FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
    ),
    'Table'[Time],
    MINUTE
)

 

 

Does this solve your issue? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Hello! Yes, that worked great! Could you help me with this new issue that I encountered? I need the "TimeDifference" to be calculated again as previously discussed, but only if the location and date are the same. 

 

this is an example of the "TimeDifference" column I want to generate. Thank you so much! 

xsaldana_0-1649280347131.png

 

Hi @xsaldana ,

 

How about this:

tomfox_0-1649358684426.png

 

Here the code:

Time Difference = 
DATEDIFF (
    CALCULATE (
        MAX ( 'Table18'[Time] ),
        FILTER ( 'Table18', 'Table18'[Index] = EARLIER ( 'Table18'[Index] ) - 1 ) , 
        FILTER ( 'Table18', Table18[Location] = EARLIER ( 'Table18'[Location] ) ), 
        FILTER ( 'Table18', Table18[Date] = EARLIER ( 'Table18'[Date] ) )
    ),
    'Table18'[Time],
    MINUTE
)

 

Let me know if this is the solution for your problem 🙂

 

Thanks!

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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