+ Reply to Thread
Results 1 to 11 of 11

Trying to get the newest date if there are multiple rows

  1. #1
    Forum Contributor
    Join Date
    05-02-2017
    Location
    NoVa, United States
    MS-Off Ver
    Microsoft 365
    Posts
    154

    Trying to get the newest date if there are multiple rows

    Okay, so I have a problem. I have a worksheet with duplicate rows with some differences. Basically what I want to do is for any row that has duplicates in column A, I want to find the max/newest date (column T). If there isn't a duplicate then I just want whatever is in column T.

    The formula is here and it works for non duplicates, but it brings up a reference error for duplicates.

    =IF(COUNTIF(A:A,A2)>1,INDEX(MAX(T:T),MATCH(A2,A:A,0)),T2)

    Any ideas?

  2. #2
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Trying to get the newest date if there are multiple rows

    =IF(COUNTIF($A:$A,$A2)=1,$T2,AGGREGATE(14,6,N(+$T$2:$T$1000)/($A$2:$A$1000=$A2),1))

    modify ranges to suit but avoid using entire column references within the AGGREGATE

  3. #3
    Forum Contributor
    Join Date
    05-02-2017
    Location
    NoVa, United States
    MS-Off Ver
    Microsoft 365
    Posts
    154

    Re: Trying to get the newest date if there are multiple rows

    Thanks - that works!

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Trying to get the newest date if there are multiple rows

    You could also just use this, array-entered with Ctrl-Shift-Enter:

    =MAX(IF($A$1:$A$1000=A2,$T$1:$T$1000))

    With newer versions, that would just be a regular formula:

    =MAXIFS($T$1:$T$1000,$A$1:$A$1000,A2)
    Bernie Deitrick
    Excel MVP 2000-2010

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Trying to get the newest date if there are multiple rows

    The check for count shouldn't be needed - this will work as well:

    =AGGREGATE(14,6,N(+$T$2:$T$1000)/($A$2:$A$1000=$A2),1)

  6. #6
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Trying to get the newest date if there are multiple rows

    Quote Originally Posted by Bernie Deitrick
    The check for count shouldn't be needed...
    Yes Bernie, but you're now performing a relatively expensive calculation when you don't need to.... not the best advice, tbh.

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Trying to get the newest date if there are multiple rows

    Quote Originally Posted by XLent View Post
    Yes Bernie, but you're now performing a relatively expensive calculation when you don't need to.... not the best advice, tbh.
    TBH - you're making some assumptions - that the values in A are not repeated. There is usually a reason for dating entries - because the other identifying values are repeated.

    With no unique values in A, your formulas took 0.02053289 seconds - and mine took 0.01809833 seconds. So, that COUNTIF is the true "expensive calculation" - good thing I had a cup of coffee for the extra time I had to wait for yours to calculate

  8. #8
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Trying to get the newest date if there are multiple rows

    ha, yes, ok...

    w/1000 unique values:

    0.0625: w/pre-emptive COUNTIF*
    0.1718: w/out pre-emptive COUNTIF

    regardless of proliferation of dupes your challenge is more than fair -- COUNTIF(S) not always the most efficient when handling the used range intersect.

    and obviously a little quicker still if the COUNTIF restricted to rows $2:$1000
    Last edited by XLent; 04-24-2020 at 10:11 AM.

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Trying to get the newest date if there are multiple rows

    And to be fair - to get anything meaningful from the OP's data set, a power query or Pivot Table would probably be a better approach - except the OP's version is 2010.

    And I think that passing a limited range to COUNTIF doesn't matter - worksheet functions actually limit themselves to the used range, as opposed to Array-entered functions that use all rows.
    Last edited by Bernie Deitrick; 04-24-2020 at 10:36 AM.

  10. #10
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Trying to get the newest date if there are multiple rows

    Hi, didn't see the above edit until just now - just in case interested...

    w.r.t. used range intersect the above does not apply to COUNTIFS (for whatever reason)
    (I confess I rather lazily assumed the same would apply to COUNTIF but I'm not convinced)

    there have been a few discussions on the above, as it's not 'documented', and pulled together the attached some months back to illustrate
    the 5000 COUNTIFS will take considerably longer than the 5000 SUMIFS... on my machine about 16s vs 0.2s

    thread has taken a detour for which I apologise.
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Trying to get the newest date if there are multiple rows

    I had not heard that about COUNTIFS - that's a big performance hit! My test showed it is 60X as long - Thanks for the tip!

+ 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. Replies: 3
    Last Post: 02-27-2020, 08:34 AM
  2. [SOLVED] Modification to the Newest file in a folder function - Getting a list of 'n' Newest files
    By yoursamrit2000 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-21-2019, 07:22 AM
  3. [SOLVED] Corresponding newest date
    By shivspatil in forum Excel General
    Replies: 3
    Last Post: 03-23-2015, 04:07 AM
  4. Arranging Pivot table data from Newest to oldest to Newest does not appear
    By paradise2sr in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-08-2014, 06:53 AM
  5. [SOLVED] lesson grades (from oldest date to newest date)
    By aaaaa34 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-04-2014, 08:40 AM
  6. [SOLVED] vba code to find Duplicate Values and Newest date(Max) date in the Corresponding Column(ce
    By Pradu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2013, 05:20 AM
  7. Returning BLANK date PRIORITY before Newest/Latest Date
    By dluhut in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-11-2013, 04:43 PM

Tags for this Thread

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