I have two datasets, which are login and logout times. Not everybody who logs in actually logs out, so the logout dataset is smaller than the login dataset. Each login and logout has a sequence ID, which is monotonically increasing across all logins and logouts of a user (but is reset to 1 every day).
I assume that the login corresponding to a logout is the one which have (a) the same user ID, (b) are of the same date, and (c) whose sequence ID is the largest, but is not larger than that of the logout entry.
Here is a sample login dataset (columns A-D):
Please Login or Register to view this content.
Here is a sample logout dataset (columns H-K):
My attempt so far has generated this formula in column L:Please Login or Register to view this content.
=SUMPRODUCT(($C$2:$C$12=J2)*($B$2:$B$12=I2)*($D$2:$D$12<=K2)*($A$2:$A$12))
The first and second parts of the sumproduct makes sure I am looking at the correct user and the correct date. The last one picks the number of the matching login entry. I am having trouble with the middle part, which picks the "max of login seq for the user on the date, but not larger than logout seq of the same user". The way it stands, it simply adds up all the numbers. I try to put a MAX() function there, the maximum of the entire column is used. I have been breaking my head here for a while now.
Please help.
Bookmarks