+ Reply to Thread
Results 1 to 38 of 38

Closest Date with Criteria (with MAXIFS formula?)

  1. #1
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Closest Date with Criteria (with MAXIFS formula?)

    I track stocks each day and if the symbol i'm tracking has had a recent reverse split, i want it to list the most recent reverse split date in Column C. So in the attached spreadsheet cell C2 should be 12/21/23 and C6 should be 12/30/23. I'm currently using a MAXIFS formula in Column C but am not quite getting the desired results. I can't use an array formula as that would seriously reduce the speed & functionality of the spreadsheet.

    Any help would be greatly appreciated. Been stuck on this for a few days now.

    Thanks,
    Impala096
    Attached Files Attached Files
    Last edited by impala096; 01-01-2024 at 04:54 PM.

  2. #2
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Closest Date with Criteria (with MAXIFS formula?)

    My proposal:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Thank you for your response. When i attempt to apply the formula I'm receiving a #NAME? result. Does this require a certain version of excel to function properly? I'm using Excel Office Professional Plus 2019.

    EDIT: I did some research it appears XLOOKUP function is only available in Excel 365 and Excel2021. It also appears to be an array formula and with the amount of data i'll be using this on an array formula will make the spreadsheet unusable. I really need a non-array solution which is why i was attempting to use MAXIFS.
    Last edited by impala096; 01-01-2024 at 06:01 PM.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,893

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Your profile states that you are using 365, so this needs amending, please.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,433

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Two other solutions (working in Excel 365 or Excel 2021):

    Try in C2 and copy down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    or try in C2 and copy down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,433

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Here is also a solution for Excel 2007 or newer:

    Please try in C2 and copy down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Note: This is an Array formula, Please confirm the formul WITH Ctrl+Shift+Enter (before copy down)
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I upgraded to Excel 2021 tonight and am now able to apply all the formulas submitted.

    Hans & DJunqueira, the formulas you provided (in Replay #2 & Reply #5) appear to be working but once the date in column A is past the last date in Column G a "no date" value is provided (for example change A6 cell to 12/31/23 and the result is "no date"). Is there a way to tweak the formula so that even if the date in cell A6 is after 12/30/23 it would still display 12/30/23?

  8. #8
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I came with that:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,433

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Please update your profile to Excel 2021.

    Please replace in the formula A2 with MIN(A2,MAXIFS(G$2:G$6,H$2:H$6,B2))

    So try in C2 and copy down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    or try in C2 and copy down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by HansDouwe; 01-02-2024 at 12:08 AM.

  10. #10
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Thank you so much DJunqueira for digging deeper into this formula. Testing it further when i change A2 value to 8/11/23, it's displaying 5/4/23 even though 8/11/23 is one of the dates that MULN had a reverse split.

    For the following tests these would be the desired results...
    If Cell A2 = 8/10/23, desired result would be 8/11/23.
    If Cell A2 = 8/11/23, desired result would be 8/11/23.
    If Cell A2 = 8/12/23, desired result would be 8/11/23.

  11. #11
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,060

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Amending DJunqueira's formula in post #2:
    =XLOOKUP(A2,($H$2:$H$6=B2)*($G$2:$G$6),$G$2:$G$6,"No date",IF(A2>MAX($G$2:$G$6),-1,1),1)

  12. #12
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I'm very appreciative to all your replies. We're close but it seems every formula provided isn't providing the desired result when Cell A2 = 8/12/23.
    If Cell A2 = 8/12/23, desired result would be 8/11/23...

    as 8/11/23 is a much closer date than 12/21/23.

  13. #13
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I did a wrong move in my second answer...

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  14. #14
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,433

    Re: Closest Date with Criteria (with MAXIFS formula?)

    In the text of post #1 you was writing about
    most recent reverse split date
    Therefore, I thought that the desired result should not be in the future (reasoned from the date in column A). Now I understand that it is possible. Then a completely different reasoning is necessary, and I would not be talking about most recent reversed split date.

    And which date do you need if the date in Column A is exact in the middle between 2 reverse split dates.

  15. #15
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,060

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Try, =IFERROR(XLOOKUP(A2,($H$2:$H$7=B2)*($G$2:$G$7),($G$2:$G$7)/($H$2:$H$7=B2),"No date",-1,IF(A2>MAX($G$2:$G$7),-1,1)),"No date")

  16. #16
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Thanks DJunqueira it still appears that when Cell A2 = 8/12/23 the result in Cell C2 is 12/21/23. The desired result would be 8/11/23 as this would be the closest date.

  17. #17
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I not in a good night...

    New formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by DJunqueira; 01-02-2024 at 12:52 AM.

  18. #18
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    What i ultimately do is track the biggest gainers in the market each day. Often these big movers can surround recent reverse stock splits. More often than not a stock will run either the very day of the split or a few days after it. But there has also been periods when a stock runs just off the announcement that a reverse split is upcoming... so it might run big 2-3 days before the split even occurs. In either case, if stock ABC runs big and there has been a recent reverse split surrounding the move, i want to track that on my excel spreadsheet. That is why i want it to display the closest day of the split.

    I do see the scenario where Column A is exactly in the middle between 2 reverse split dates. In that case i don't really care which date it selects to be closer, as it will be so far out from either reverse split date anyways... in practice these reverse splits for a stock will only happen 2-3 times a year. Really anything past 10 days out either direction the data becomes less meaningful for my purposes. I hope this at least helped explain more what i'm trying to do with this data.

  19. #19
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I deal with stock too, I understand pretty well what you want.

  20. #20
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,433

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I upgraded to Excel 2021 tonight
    Repeating my request in Post #9:

    Please update your MS-Off Ver in your profile, there is Office 365 in, but it should be Excel 2021.

    Otherwise we waste our time developing formulas that you cannot use and you may be presented with formulas that cause #NAME for you.
    Last edited by HansDouwe; 01-02-2024 at 01:57 AM.

  21. #21
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I updated my profile version earlier tonight to show "Excel 2021". Hopefully it showing up correctly now.

  22. #22
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,433

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Thanks, your profile is showing up correctly now.

    Here is a formula that should work in Excel 2021

    Please try"in C2 and copy down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  23. #23
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Hans, your formula in Reply#22 appears to be working perfectly.

    =LET(f,FILTER(F$2:F$6,G$2:G$6=B2),IFERROR(XLOOKUP(TRUE,ABS(A2-f)=MIN(ABS(A2-f)),f),"No date"))

    Thank you for your persistence and providing that awesome formula!

  24. #24
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,433

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Thanks for the feedback.

    Glad to have helped.

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.

  25. #25
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Hans, would it be possible to use a formula that would lead to the same results but that would be compatible with Excel 2016? Unfortunately some of the users I'm collaborating with are not on the most recent version of Excel (where the filter command is not available).

  26. #26
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I'm really in a bind to get this spreadsheet working again. Is there any way to reformat the equation to be compatible with earlier versions of Excel?

    This is the equation that works, trying to create the same results without using XLOOKUP or FILTER or MAXIFS:

    =LET(f,FILTER(F$2:F$6,G$2:G$6=B2),IFERROR(XLOOKUP(TRUE,ABS(A2-f)=MIN(ABS(A2-f)),f),"No date"))

  27. #27
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Lets see if it does the job for you.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  28. #28
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Thank you DJunqueira. That equation is working but for whatever reason the equation is causing the spreadsheet to bog down a lot. The equation is giving the desired results but it's much more sluggish now.

    The MAXIF equation you provided previously in this thread also works (and doesn't cause any sluggishness), but for whatever reason when i open the spreadsheet it randomly decides not to function... half the time i get "_xlfn.MAXIFS" to display in the formula, indicating my version of excel isn't registering the formula. I'm so confused i can't even really explain what's happening.

    My version of excel is Version 2108 (Build 14332.20637). I have no idea why my MAXIFS function is randomly working on some days and doesn't work on others.

  29. #29
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Closest Date with Criteria (with MAXIFS formula?)

    MAXIF is an Excel 2019 function, it should work fine.

  30. #30
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I really have no idea why MAXIFS isn't always working with my latest version of Excel 2021. It's even more frustrating that it works certain days and decides to not work the next day. This is becoming difficult to troubleshoot.

  31. #31
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Closest Date with Criteria (with MAXIFS formula?)

    You may have a corrupted file, you could try to pass the data to another new file, but with care because you may transfer the corrupted part too. I just deal with a file corrupted in another tread, it was difficult to select columns in a named table, I further investigate and M$ pointed to this possibility. Interestingly it got smaller as I finished the transfer.

  32. #32
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Thank you for your responses DJunqueira.

    When trying to transfer the data to a new fresh spreadsheet, the xlfn.MAXIFS is showing up, but admittedly i wasn't very careful with the transfer yet (was just a bulk transfer of data.. i'm going to try to recreate the spreadsheet from scratch now).

    One interesting thing i've noticed is if i open a fresh blank spreadsheet and then open the spreadsheet of interest, the MAXIFS formula is working properly. So i guess one workaround is opening a blank spreadsheet first before opening my main spreadsheet. Any ideas what might cause that? It seems like i did stumble upon a workaround if nothing else.

  33. #33
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I see it as a sign of corrupted file, transfer you data before it is too late and do a backup.

  34. #34
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I created a very simple spreadsheet from scratch using a MAXIFS formula...

    =MAXIFS(A1:A5,B1:B5,C1)

    Where A1:A5 were random dates, B1:B5 were random letters, and C1 was a random letter. The spreadsheet worked as desired.

    Once i saved the spreadsheet and reopened it, it displayed "_xlfn.MAXIFS" and it no longer was working.

    No idea what is happening. Why am i able to create the formula perfectly, but upon saving and reopening it no longer works? What's really confusing, is when i have a blank spreadsheet open and then try to open the simple MAXIFS spreadsheet i created, then the formula does work properly.
    Attached Files Attached Files
    Last edited by impala096; 03-16-2024 at 11:18 PM.

  35. #35
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Closest Date with Criteria (with MAXIFS formula?)

    Your file worked as expected with me.
    Can't say exactly what is going on with your files, maybe Office installation or problem with HD, you will need to test and try to talk with Microsoft.

  36. #36
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,893

    Re: Closest Date with Criteria (with MAXIFS formula?)

    MAXIFS was a new Excel function in Excel 2019 - are you SURE that you are using Excel 2021 and not something older?

  37. #37
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Closest Date with Criteria (with MAXIFS formula?)

    I'm positive I'm using Excel 2021... Version 2108 (Build 14332.20637).

    I found that the MAXIFS function will work properly in the spreadsheet if I first open the base excel program. The problem of MAXIFS not working arises when I double click my spreadsheet directly without first opening up the base Excel program.

    I created a very simple spreadsheet from scratch with a simple MAXIFS formula. The same behavior is occurring (MAXIFS function not working upon reopening the spreadsheet directly... MAXIFS will work if i open the base program first before opening).

  38. #38
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,893

    Re: Closest Date with Criteria (with MAXIFS formula?)

    It sounds as if double-clicking on a file is opening an OLDER version of Excel that is still installed on your machine. Check in Windows that the file associations are correct and check in your Programs folder that you don't still have an older Office installation lurking there. If you have a Mac, you'll need to do whatever is necessary (can't help with that).

+ 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: 11
    Last Post: 06-05-2023, 01:36 AM
  2. Additional criteria to a maxifs formula
    By JaySanctuary in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-14-2023, 11:01 AM
  3. [SOLVED] How to use MOD as a criteria in MAXIFS formula or any other solution to my problem
    By Govind0186 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-28-2020, 12:47 PM
  4. MAXIFS formula that excludes based on date
    By xavior1325 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-11-2019, 01:41 PM
  5. Replies: 4
    Last Post: 10-27-2015, 02:00 PM
  6. Index formula and matching 2 criteria; 1 relating to a closest date
    By fordieuk in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-05-2013, 03:59 AM
  7. How to lookup value based on Date time closest to criteria
    By ilionel1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-08-2013, 02:01 PM

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