Home » excel » Excel: Difference in hours between duplicates

Excel: Difference in hours between duplicates

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am having a problem, hope you can help.

I need to have the differente in hours between duplicates. Example:

Date Time           |   SESSION_ID  |  Column I need

24/01/2020 10:00    |   100         |  NaN

24/01/2020 11:00    |   100         |  1

14/03/2020 12:00    |   290         |  NaN

16/03/2020 13:00    |   254         |  NaN

16/03/2020 14:00    |   100         |  1251

In session_ID column, there are 3 duplicates with value 100.

I need to know the difference in hours between those sessions, which would be 1 hour between the first and the second, and 1 251 hours between the second and the third.

Does anyone has any type of clue on how this could be done?

Thank you so much for your help

Stay safe,

Alena

How to&Answers:

If one has the Dynamic Array formula XLOOKUP, put this in C2 and copy down:

=IF(COUNTIF($B$1:B1,B2),A2-XLOOKUP(B2,$B$1:B1,$A$1:A1,,0,-1),"NaN")

Then format the column: [h]

![enter image description here

If not then use INDEX/AGGREGATE in its place:

=IF(COUNTIF($B$1:B1,B2),A2-INDEX(A:A,AGGREGATE(14,7,ROW($B$1:B1)/($B$1:B1=B2),1)),"NaN")

![enter image description here