+ Reply to Thread
Results 1 to 11 of 11

Optimizing the Formula to run faster Finding the latest record

  1. #1
    Registered User
    Join Date
    12-04-2012
    Location
    india
    MS-Off Ver
    2021
    Posts
    45

    Optimizing the Formula to run faster Finding the latest record

    Hi,

    I have a sheet with more than 100k records. Service name is in column B, while the date it was scanned is available in columns j:o.

    Formula in
    column H will calculate if it is the latest record (based on the date for this service) (=IF(K2=AGGREGATE(14,6,K$2:K$89750/(D$2:D$89750=D2),1),"Yes","No"))
    column I will calculate if the record is a latest one in that particular month. (=IF(K2=AGGREGATE(14,6,K$2:K$89750/(D$2:D$89750=D2)/(O$2:O$89750=O2),1),"Yes","No"))

    Ex: ABC service would have been scanned for more than 2 years, so that last scan when it was done is calculated in H. irrespective of the month.
    ABC service might have multiple scans in a particular month, the latest scan in that particular month is calculated in Column I .

    While the formula is correct, the excel sheet hangs up when calculating the records multiple times .

    Any operation i do, insert or edit takes huge amount of time and excel freezes, takes more than 8 minutes for just saving the file.

    using Excel 2010.

    Is there a way this formula can be optimized?

    sample sheet is attached.


    Appreciate the help.
    Attached Files Attached Files
    Last edited by zaveed; 04-19-2022 at 04:29 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    01-07-2022
    Location
    Europe
    MS-Off Ver
    Office 365
    Posts
    473

    Re: Optimizing the Formula to run faster Finding the latest record

    You can try this alternate logic for a maximum If with multiple criteria. It may not perform much better than what you have already though as its an array formula, but worth a try: https://exceljet.net/formula/maximum...tiple-criteria

    Aside from that some options are:
    -switch to manual calculation mode
    -upgrade to a newer version of excel that has MAXIFS formula
    -calculating using VBA
    -installing the PowerQuery add-in for Excel 2010.

    Lastly, be careful with the logic for 'Latest in that Month' as you might not get the desired results if working across multiple years. If its an issue, you can change cell O2 to something like =TEXT(L2,"mmm yy") or =EOMONTH(L2,-1)+1
    <<< If you have valued anyone's contributions in this thread, please click * to thank them for their efforts

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,036

    Re: Optimizing the Formula to run faster Finding the latest record

    AGGREGATE will not be the cause of your problem... even over 13,000 rows. Something else in your file will be causing the issue. Do you have array formulae using whole column references... or SUMPRODUCT with whole column references, etc??
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  4. #4
    Registered User
    Join Date
    12-04-2012
    Location
    india
    MS-Off Ver
    2021
    Posts
    45

    Re: Optimizing the Formula to run faster Finding the latest record

    Quote Originally Posted by Glenn Kennedy View Post
    AGGREGATE will not be the cause of your problem... even over 13,000 rows. Something else in your file will be causing the issue. Do you have array formulae using whole column references... or SUMPRODUCT with whole column references, etc??
    Hi Glenn,

    No, those are the only formulas in the excel sheet and this sheet has 2,33,456 rows of data and columns till AI.

    Thank you

  5. #5
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Optimizing the Formula to run faster Finding the latest record

    Please try
    for Latest
    =IF(COUNTIFS(D$2:D$89750,D2,K$2:K$89750,">"&K2)+(K2=0),"No","Yes")

    Latest in that Month without Year
    =IF(COUNTIFS(D$2:D$89750,D2,K$2:K$89750,">"&K2,$O$2:$O$89750,O2)+(K2=0),"No","Yes")

    Latest in that Month with Year
    =IF(COUNTIFS(D$2:D$89750,D2,K$2:K$89750,">"&K2,K$2:K$89750,"<"&EOMONTH(K2,0)+1)+(K2=0),"No","Yes")
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    12-04-2012
    Location
    india
    MS-Off Ver
    2021
    Posts
    45

    Re: Optimizing the Formula to run faster Finding the latest record

    Quote Originally Posted by Bo_Ry View Post
    Please try
    for Latest
    =IF(COUNTIFS(D$2:D$89750,D2,K$2:K$89750,">"&K2)+(K2=0),"No","Yes")

    Latest in that Month without Year
    =IF(COUNTIFS(D$2:D$89750,D2,K$2:K$89750,">"&K2,$O$2:$O$89750,O2)+(K2=0),"No","Yes")

    Latest in that Month with Year
    =IF(COUNTIFS(D$2:D$89750,D2,K$2:K$89750,">"&K2,K$2:K$89750,"<"&EOMONTH(K2,0)+1)+(K2=0),"No","Yes")
    Thank you . Latest formula works.

    Latest in that month with year is showing incorrect results, find attached excel sheet . Column I row 32-46 should be No because the service ABC has been run on multiple dates in the same month, however the formula shows as Yes which is incorrect. Same case with 51-61,68-71 rows too. Please check .
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,193

    Re: Optimizing the Formula to run faster Finding the latest record

    Using Bo_Ry's formula from Column R gives correct results Using column K not J)
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  8. #8
    Registered User
    Join Date
    12-04-2012
    Location
    india
    MS-Off Ver
    2021
    Posts
    45

    Re: Optimizing the Formula to run faster Finding the latest record

    Quote Originally Posted by JohnTopley View Post
    Using Bo_Ry's formula from Column R gives correct results Using column K not J)
    Thank you Got it. But unfortunately this is also taking more than 5 minutes for the formula, and after that if i have to apply a filter or remove a filter it takes more than 5 min for each operation. Not sure if the issue is with Excel or my laptop now.

    Thanks
    Last edited by zaveed; 04-19-2022 at 06:33 AM.

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,193

    Re: Optimizing the Formula to run faster Finding the latest record

    What is your laptop spec?

  10. #10
    Forum Expert
    Join Date
    12-09-2014
    Location
    Trakai, Lithuania
    MS-Off Ver
    2016
    Posts
    1,292

    Re: Optimizing the Formula to run faster Finding the latest record

    And if you apply Power Query?
    Please Login or Register  to view this content.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    12-04-2012
    Location
    india
    MS-Off Ver
    2021
    Posts
    45

    Re: Optimizing the Formula to run faster Finding the latest record

    Quote Originally Posted by JohnTopley View Post
    What is your laptop spec?
    Processor Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz, 2712 Mhz, 2 Core(s), 4 Logical Processor(s), 8 Gigs of RAM.
    I cannot copy this data to my personal laptop and work because of data privacy clauses.

    Thanks

+ 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. [SOLVED] access database. Finding the latest status of a record between two tables.
    By svsands26 in forum Access Tables & Databases
    Replies: 2
    Last Post: 10-16-2019, 08:39 PM
  2. Replies: 1
    Last Post: 02-23-2018, 06:38 PM
  3. Replies: 3
    Last Post: 12-08-2015, 11:36 AM
  4. Finding latest data record with different dates
    By Rubyod in forum Excel General
    Replies: 4
    Last Post: 04-10-2015, 12:44 AM
  5. Highlight the latest record
    By ihinojosajr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-22-2014, 04:37 PM
  6. [SOLVED] Excel 2007 : Finding the latest data based on 2 variables
    By Dr Martin in forum Excel General
    Replies: 2
    Last Post: 06-28-2010, 11:50 AM
  7. Finding the newest / latest date in each record
    By Statsman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-01-2009, 07:40 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