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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.