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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Josh97Ellis
Helper III
Helper III

Calculating time between two rows in the same column

Hi, 

 

I am trying to create a new column that displays the how many minutes have passed between each row in the [Time] Column. Basically, I just need to subtract the bottom row from the above row for all rows. Here's what I have tried, but there is not enough memory to complete the operation. I am wondering if anyone knows a better way around this. 

 

Josh97Ellis_1-1596643733299.png

 

 

1 ACCEPTED SOLUTION

 🙂@Josh97Ellis 

 

Diff =
VAR __Previous =
    MINX (
        FILTER (
            'Table',
            'Table'[Date] = EARLIER ( 'Table'[Date] )
                && 'Table'[Time] > EARLIER ( 'Table'[Time] )
        ),
        'Table'[Time]
    )
VAR __diff = __Previous - 'Table'[Time]
RETURN
    __diff



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂

 

 


Regards,
Nandu Krishna

View solution in original post

13 REPLIES 13
lit2018pbi
Resolver II
Resolver II

Hi Josh,

 

Step 1: You can add a new column tp concatenate date and time using the following Dax

            Date and Time = CONCATENATE('time diff'[Date].[Date]&" ",'time diff'[Time])
concat.PNG

 Step 2: Now find the Lag Date and Time using the following Dax

     Lag Date and Time = CALCULATE(MAX('time diff'[Date and Time]),FILTER('time diff','time diff'[Material] = EARLIER('time diff'[Material])&&'time diff'[Date and Time]<EARLIER('time diff'[Date and Time])))
Lag.PNG

 Step 3: Find out the time difference using the following Column

            Difference in Minutes = DATEDIFF('time diff'[Lag Date and Time],'time diff'[Date and Time],MINUTE)

Difference.PNG

 

There are many steps involved here but you will get the result by implementing the above!
Thanks!
 

This was so helpful for me! I needed to calculate a time difference based on an ID, and this did so perfectly!

v-lionel-msft
Community Support
Community Support

Hi @Josh97Ellis ,

 

Like this?

v-lionel-msft_0-1596681911097.png

Or like this?

v-lionel-msft_1-1596682031117.png

Or @nandukrishnavs 's formula?

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-lionel-msft Hi, I need it to be the number of minutes (duration) between each time stamp. So in excel, it would look like this:

 

Josh97Ellis_1-1596726659092.png

 

Greg_Deckler
Super User
Super User

@Josh97Ellis - See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
nandukrishnavs
Super User
Super User

@Josh97Ellis 

 

Try this 

Diff =
VAR __Previous =
    MAXX (
        FILTER (
            'Table',
            'Table'[Date] = EARLIER ( 'Table'[Date] )
                && 'Table'[Time] < EARLIER ( 'Table'[Time] )
        ),
        'Table'[Time]
    )
VAR __diff = 'Table'[Time] - __Previous
RETURN
    __diff



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

@nandukrishnavs  This is close, it looks like it needs to be "shifted up" one row. So basically, the value I get in row 2 should be the value for row 1, etc.. You'll see that in the picture. 

 

Josh97Ellis_0-1596727205695.png

 

pls, I am also stuck here. The value in row 2, should be in row 1

 

 

@Josh97Ellis you have to change colum formatting.

Set the data type as Time. Format as HH:mm



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

@nandukrishnavs Yeah, i got the format correct after I sent that, I was just in the wrong place. 

 

How can I adjust the formula so that each row in that calculated column is essentially shifted up one row. per my last reply. 

 

Thanks

 🙂@Josh97Ellis 

 

Diff =
VAR __Previous =
    MINX (
        FILTER (
            'Table',
            'Table'[Date] = EARLIER ( 'Table'[Date] )
                && 'Table'[Time] > EARLIER ( 'Table'[Time] )
        ),
        'Table'[Time]
    )
VAR __diff = __Previous - 'Table'[Time]
RETURN
    __diff



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂

 

 


Regards,
Nandu Krishna

Good afternoon @nandukrishnavs.

I have a similar situation. I tried the two recommended solutions, resulting in what is shown in the following image:

RichardFig1_0-1632865434549.png

Sometimes it works, so the solution I need should not be far away. To explain my case, each row represents a movement (or modification of the ticket) this group for a help desk ticket (14 movements). I have a column with the date and another with the modification time. I also concatenated both columns in the "Date & Time" column.

I need to calculate how much time passed between each movement. For example, from the first move to the second passed 00h:40m:59s.

The result can be in duration format or could indicate the number of seconds in total and then convert it to minutes or hours.

I hope you can help me.

Best regards

Richard

amitchandak
Super User
Super User

@Josh97Ellis , Try like

diff =
var _max = maxx(filter(Table, [date] = earlier([date]) && [time] < earlier([time]) && [material] = earlier([material])),[time])
return
[time] - maxx(filter(Table, [date] = earlier([date]) && [time] = _max && [material] = earlier([material])),[time])

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

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.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

Top Solution Authors