+ Reply to Thread
Results 1 to 17 of 17

Trying to find max date in 1 column for selected text in another column

  1. #1
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Trying to find max date in 1 column for selected text in another column

    I have 2 columns: Locations (Column A) & Dates (Column B).
    I want to find the most recent date for a selected Location (stored in $G$1).

    currently I have in C2: =If($A2=$G$1,$B2,"") copied down the column to the end of data (currently C153). Then in C1: =Max(C$2:C$153).

    I also have in D2: =If($C2<$C$1,$C2,"") copied down to D153, and in D1: =Max(D$2:D$153) to find the 2nd most recent date.

    Is there some way to condense this into just 2 cells?

    See attached file for example (note the columns are currently sorted by date, but that is not always the case).
    Attached Files Attached Files
    Last edited by foxguy; 04-11-2009 at 07:20 PM.

  2. #2
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Trying to find max date in 1 column for selected text in another column

    Try the following formulas, which need to be confirmed with CONTROL+SHIFT+ENTER...

    =MAX(IF(A2:A153=G1,B2:B153))

    and

    =LARGE(IF(A2:A153=G1,B2:B153),2)

  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Trying to find max date in 1 column for selected text in another column

    Thanks, I guess I'll have to start using Array formulas. I've been avoiding learning about them till now. And the Large function is new to me, guess I'll have to go through the entire list of functions to see what else I don't know about.

    I am curious, Is Max() more effecient that Large(). Wouldn't Large work in the 1st formula also?
    Last edited by foxguy; 04-11-2009 at 07:22 PM.

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Trying to find max date in 1 column for selected text in another column

    Appreciate this is Solved but thought I would take the opportunity to add another alternative which is non-array but much less elegant... and so I can ascertain Dominic's opinion on the efficiency of the approach...

    Latest date
    =INDEX($B$2:$B$153,MATCH(TRUE,INDEX($A$2:$A$153=$G$1,0),0))

    2nd from last date
    =INDEX($B$2:$B$153,MATCH(1,INDEX(($A$2:$A$153=$G$1)*($B$2:$B$153<$I1),0),0))

    Note: this is flawed if there are ever two meetings on the same day whereas LARGE CSE will handle this.


    Dominic, would you say the above are hideously inefficient ? As you know I like to know your opinion. I picked up this method using INDEX with TRUE to avoid CSE the other day from reading one of daddylonglegs' posts and I confess that like it... I know that using the LOOKUP(2,1/....) is regarded as slow and given this approach is doing a similar thing albeit in a different direction I presume the same is true here ... ?

  5. #5
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Trying to find max date in 1 column for selected text in another column

    DonkeyOte: what is "CSE"?

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Trying to find max date in 1 column for selected text in another column

    [C]trl [S]hift [E]nter - ie Array.

  7. #7
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Trying to find max date in 1 column for selected text in another column

    DonkeyOte: Your formulas don't accomplish what I need. I believe they depend on the ranges being sorted in descending date order, which is not always true. But it was very interesting trying to figure out why they didn't work.

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Trying to find max date in 1 column for selected text in another column

    Quote Originally Posted by foxguy
    I believe they depend on the ranges being sorted in descending date order
    Correct. In the sample file everything was listed in Desc order but if as you say if this is not always the case then I agree it's a null and void approach.

    Dominic, if/when you have the time I would still like your opinion re: efficiency of this approach...

    Cheers,
    DO

  9. #9
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Trying to find max date in 1 column for selected text in another column

    DonkeyOte: I'm trying to learn from you. I can't get "=INDEX($B$2:$B$153,MATCH(1,INDEX(($A$2:$A$153=$G$1)*($B$2:$B$153<$I1),0),0))" to work.
    I'm guessing that the "$I1" is a typo, that it really should be "$C$1" (where I put the result of the 1st formula), but it still doesn't work.
    Can you walk me through the logic here?

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Trying to find max date in 1 column for selected text in another column

    Yes, it should be $C1 (I was testing in J1 - ie not overriding your results)

    You say it still doesn't work - so I can test - what is G1 set to / and is this using the same sample ? Also, can you confirm which XL version you're running ? (your profile would indicate 2002)

  11. #11
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Trying to find max date in 1 column for selected text in another column

    I'm using XL 2002. Same Sample file. G1 is set to "Barstow". Your first formula correctly finds the highest date.

  12. #12
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Trying to find max date in 1 column for selected text in another column

    Actually, it does work in the sample file. I guess I'm having trouble translating it into my actuall file (that currently has 352 rows, and column A is really a concantenation of 2 other columns). I'll keep working on it.

  13. #13
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Trying to find max date in 1 column for selected text in another column

    Found my typo.

  14. #14
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Trying to find max date in 1 column for selected text in another column

    Unfortunately, I can't offer a definitve answer. However, after some informal testing, here's what I found...

    MAX(…) vs LARGE(…,1)
    It looks like they both take about the same amount of time to calculate. So it doesn't look like there's any real difference between the two, if any.

    MAX(...) vs INDEX($B$2:$B$153,MATCH(TRUE,INDEX($A$2:$A$153=$G$1,0),0))
    It looks like INDEX/MATCH is a bit faster. However, I don't think the difference in speed has anything to do with the fact that INDEX/MATCH is confirmed with just ENTER, as apposed to CSE. For both formulas, there's an initial computational array ($A$2:$A$153=$G$1). After that, INDEX/MATCH finds the first match, which I believe is faster than finding the maximum value.

    INDEX($B$2:$B$153,MATCH(1,INDEX(($A$2:$A$153=$G$1)*($B$2:$B$153<$I1),0),0))
    This seems to be slower. Probably because here we have two computational arrays.

  15. #15
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Trying to find max date in 1 column for selected text in another column

    DonkeyOte, Is there a way to avoid creating a concantination column for your formula section "MATCH(TRUE,INDEX($A$2:$A$153=$G$1,0),0)"?
    Where A2 = "+H2&I2"
    Something like "MATCH(TRUE,INDEX(($H$2:$H$153)+($I$2:$I$153)=$G$1,0),0))"

  16. #16
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Trying to find max date in 1 column for selected text in another column

    Concatenate the two

    =MATCH(TRUE,INDEX($H$2:$H$153&$I$2:$I$153=$G$1,0),0)

    Per Dominic's note there's no gain using this approach over the standard Array approach other than not having to set the array ... and in fact performance may not be as good.

  17. #17
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Trying to find max date in 1 column for selected text in another column

    Quote Originally Posted by DonkeyOte View Post
    Concatenate the two

    =MATCH(TRUE,INDEX($H$2:$H$153&$I$2:$I$153=$G$1,0),0)

    Per Dominic's note there's no gain using this approach over the standard Array approach other than not having to set the array ... and in fact performance may not be as good.
    Actually, as per my post, this approach -- without concatenation -- is somewhat faster. However, as you've already indicated, the data needs to be sorted by date, in descending order. Surprisingly, though, when concatenation is used with this approach, Excel is brought to a virtual standstill.
    Last edited by Domenic; 04-13-2009 at 12:01 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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