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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
gwstew01
Frequent Visitor

Calculating time difference between two entries based on Name

I am attempting to calculate the time between user entries based on a sample dataset below. Everything I have tried returns a blank when the previous user is different.  I would like to create a calculated column that states the time in minutes from the users last entry. Thank you in advance, any help would be greatly appreciated. 

 

ID

Start time

NameSerial 
11/4/2023 6:07JoeFA2959059
21/4/2023 6:10BobEA1718776
31/4/2023 6:11JoeEZ7876073
41/4/2023 6:17BobFA8496490
51/4/2023 6:00TomIO6534201
61/4/2023 6:26TomDX5874653
71/4/2023 6:26TomFA7756353
81/4/2023 6:29JoeEC3715128
91/4/2023 6:22BobDP5017825
101/4/2023 6:35BobDQ7629157
111/4/2023 6:26TomIU0097619
121/4/2023 6:46TomIO1884803
131/4/2023 6:46TomFB6047252
141/4/2023 6:49JoeDP5933893
151/4/2023 6:51BobDQ7257435
161/4/2023 6:57JoeDQ7543159
171/4/2023 7:03JoeFA7563565
181/4/2023 7:01BobDP5079926
191/4/2023 6:46TomII0894636
201/4/2023 7:15TomEH0771377
211/4/2023 7:15TomFA6843160
221/4/2023 7:18JoeDQ7162684
231/4/2023 7:10BobDQ7247192
241/4/2023 7:21BobDP5842204
251/4/2023 7:27BobDP5071737
261/4/2023 7:26JoeEA1488343
271/4/2023 7:35JoeII0947655
281/4/2023 7:38BobDM4342578
291/4/2023 7:55JoeFA2972328
301/4/2023 7:15TomCY9930105
311/4/2023 8:10TomDP5841874
321/4/2023 8:10TomDQ7692967
331/4/2023 8:04JoeDP5860356
341/4/2023 8:09BobDP4964209
351/4/2023 8:17JoeDP5606351
361/4/2023 8:14BobDP5779962
371/4/2023 8:26BobDP5775000
381/4/2023 8:17JoeDQ7567956
391/4/2023 8:35BobDQ5960622
401/4/2023 8:35BobDQ5960622
411/4/2023 8:32JoeDP5942894
421/4/2023 8:41BobDM4152731
431/4/2023 8:39JoeDP5983077
441/4/2023 8:47JoeFA7300814
451/4/2023 8:47BobDP6063608
461/4/2023 9:00Bob978447576
471/4/2023 9:02Bob978447576
481/4/2023 8:57JoeEJ5744252
491/4/2023 9:11BobDR7238885
501/4/2023 9:16JoeDR6832921
2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @gwstew01 ,

I have created a simple sample, please refer to my pbix file to see if it helps you.

Create a measure.

Measure =
VAR _min =
    CALCULATE (
        MAX ( 'Table'[ID] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[ID] < SELECTEDVALUE ( 'Table'[ID] )
                && 'Table'[Name] = SELECTEDVALUE ( 'Table'[Name] )
        )
    )
VAR _1 =
    CALCULATE (
        MAX ( 'Table'[Start time] ),
        FILTER ( ALL ( 'Table' ), 'Table'[ID] = _min )
    )
VAR _result =
    MINUTE ( MAX ( 'Table'[Start time] ) - _1 )
VAR _minid =
    CALCULATE (
        MIN ( 'Table'[ID] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Name] = SELECTEDVALUE ( 'Table'[Name] ) )
    )
RETURN
    IF ( MAX ( 'Table'[ID] ) = _minid, BLANK (), _result )

vpollymsft_0-1673227171825.png

Best Regards
Community Support Team _ Polly

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

View solution in original post

Hi,

This calculated column formula should work

=Data[Start time]-COALESCE(CALCULATE(MAX(Data[Start time]),FILTER(Data,Data[name]=EARLIER(Data[name])&&Data[Start time]<EARLIER(Data[Start time]))),Data[Start time])

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
gwstew01
Frequent Visitor

@Ashish_Mathur @Anonymous both of your most recent solutions work, thank you both so much!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
gwstew01
Frequent Visitor

@Anonymous thank you for your reply, but it doesnt look like the provided solution works. What I am looking for is the below. For example: Joe's first entry was at 6:07 (ID=1) his next entry was at 6:11 (ID=3), I am trying to calculate the difference between these two times and get the result of 4 minutes. His next entry was at 6:29 (ID=8), so the result should be 18 minutes (6:11 to 6:29 is 18 minutes elapsed time). Hopefully this helps. 

 

IDStart timeNameSerial Time in minutes
11/4/2023 6:07JoeFA2959059 
21/4/2023 6:10BobEA1718776 
31/4/2023 6:11JoeEZ78760734
41/4/2023 6:17BobFA84964907
51/4/2023 6:00TomIO6534201 
61/4/2023 6:26TomDX587465326
71/4/2023 6:26TomFA77563530
81/4/2023 6:29JoeEC371512818
91/4/2023 6:22BobDP50178255
101/4/2023 6:35BobDQ762915713

Hi,

This calculated column formula should work

=Data[Start time]-COALESCE(CALCULATE(MAX(Data[Start time]),FILTER(Data,Data[name]=EARLIER(Data[name])&&Data[Start time]<EARLIER(Data[Start time]))),Data[Start time])

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @gwstew01 ,

I have created a simple sample, please refer to my pbix file to see if it helps you.

Create a measure.

Measure =
VAR _min =
    CALCULATE (
        MAX ( 'Table'[ID] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[ID] < SELECTEDVALUE ( 'Table'[ID] )
                && 'Table'[Name] = SELECTEDVALUE ( 'Table'[Name] )
        )
    )
VAR _1 =
    CALCULATE (
        MAX ( 'Table'[Start time] ),
        FILTER ( ALL ( 'Table' ), 'Table'[ID] = _min )
    )
VAR _result =
    MINUTE ( MAX ( 'Table'[Start time] ) - _1 )
VAR _minid =
    CALCULATE (
        MIN ( 'Table'[ID] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Name] = SELECTEDVALUE ( 'Table'[Name] ) )
    )
RETURN
    IF ( MAX ( 'Table'[ID] ) = _minid, BLANK (), _result )

vpollymsft_0-1673227171825.png

Best Regards
Community Support Team _ Polly

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

Anonymous
Not applicable

Hi @gwstew01 ,

I have created a simple sample, please refer to it to see if it helps you.

Create a measure.

Measure = var _maxdate=CALCULATE(MAX('Table'[start time]),FILTER(ALL('Table'),'Table'[name]=SELECTEDVALUE('Table'[name])))
return
_maxdate-MAX('Table'[start time])

vpollymsft_0-1672971115840.png

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors