+ Reply to Thread
Results 1 to 7 of 7

How to find max value of a column which is less than a cell?

  1. #1
    Registered User
    Join Date
    06-17-2014
    Location
    Mumbai, India
    MS-Off Ver
    2013
    Posts
    3

    How to find max value of a column which is less than a cell?

    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):

    Please Login or Register  to view this content.
    My attempt so far has generated this formula in column L:

    =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.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,622

    Re: How to find max value of a column which is less than a cell?

    isn't it enough just to use MAX rather then SUMPRODUCT but .. commit it as array formula (with Ctrl+Shift+Enter not just Enter alone):
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    PS. next time rather attach sample workbook than copy text from it's contents.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    06-17-2014
    Location
    Mumbai, India
    MS-Off Ver
    2013
    Posts
    3

    Re: How to find max value of a column which is less than a cell?

    Quote Originally Posted by Kaper View Post
    isn't it enough just to use MAX rather then SUMPRODUCT but .. commit it as array formula (with Ctrl+Shift+Enter not just Enter alone)
    My other research also suggested such an approach, but I didn't quite get it right.

    Quote Originally Posted by Kaper View Post
    PS. next time rather attach sample workbook than copy text from it's contents.
    Here is a sample workbook. Apologies for not attaching it earlier. What I need is the formula in column L to reflect the manual matching I have done in column M. Take the example of the highlighted rows - on the right-hand (logout) side, user A on 1/1 has Seq of 4. On the left-hand (login) side, user A on 1/1 has two Seqs - 1 & 3. The match should be the largest of these which is smaller than 4. The required output is the number from column A corresponding to the match (row 5, No = 4).

    Edit: It is guaranteed that for a given user on a given day, all the Seqs are unique.
    Attached Files Attached Files

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,622

    Re: How to find max value of a column which is less than a cell?

    I still think MAX committed as array formula is right.
    See attached with:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    CSE, not just Enter!
    note two green rows - there is the same data, so the output in column L is the same. but in column M you gave different values (red cells) - probably because your sample data is not unique - see rows 6 and 11 in columns B:D.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-17-2014
    Location
    Mumbai, India
    MS-Off Ver
    2013
    Posts
    3

    Re: How to find max value of a column which is less than a cell?

    Thanks for that. It works now. I was doing the MAX only for the third array, which was the mistake.

    My actual data has 100K+ rows, and it takes hours for this formula to produce data on a i5 laptop. But such is the price...

  6. #6
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: How to find max value of a column which is less than a cell?

    Non-array alternative

    =MAX(INDEX(($C$2:$C$12=J2)*($B$2:$B$12=I2)*($D$2:$D$12<=K2)*$A$2:$A$12,),0)

    Should reduce processing time for sure!
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  7. #7
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,622

    Re: How to find max value of a column which is less than a cell?

    Quote Originally Posted by Ace_XL View Post
    Should reduce processing time for sure!
    Could be, but as a matter of fact it is anyway an array formula, even if it is not CSE one.
    So could be somawhat quicker, but not super-quick?
    As a matter of fact, I tried both methods (not run proper tests) with the same data as in sample file copied down 20K rows.
    Wrote first formula in row 2, copied down - recalculation (also i5 laptop) went roughly 1-2% per second. deleted whole colun, wrore second formula in row 2, copied and ... very similar speed.
    As I said no proper test, no timer, just looking at progress info on status bar, but if there is a difference, it not impressive - because it is anyway array formula by nature.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Find 1st unique Value on Column and Insert certain Word on cell on left Column
    By Wldlife23 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-16-2013, 10:02 AM
  2. [SOLVED] Macro to find the empty cell in a column and copy a adjacent row to another column.
    By naga in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-18-2013, 07:44 AM
  3. macro to find first blank cell in a column cut the value from left adjacent column
    By willykin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-01-2012, 09:23 AM
  4. Range.Find to find column and place value in next available cell in one line
    By davegugg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2011, 10:41 AM
  5. Replies: 8
    Last Post: 08-06-2009, 09:02 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1