+ Reply to Thread
Results 1 to 9 of 9

XLOOKUP and dates with multiple criteria.

  1. #1
    Registered User
    Join Date
    02-13-2022
    Location
    Cardiff, Wales
    MS-Off Ver
    Microsoft 365 for Mac
    Posts
    3

    XLOOKUP and dates with multiple criteria.

    I'm struggling with XLOOKUP and dates with multiple criteria.
    I'm trying to return a Lab value for a particular ID collected on a date that is closest to, but before, or equal to, the Clinic Date.
    For example, to return the closest lab value for ID: A251527 on Clinic Date 17/09/2008 (in cells E2 and F2 respectively).
    The answer should be 130 on 12/08/2008 but XLOOKUP using multiple criteria seems to return the Lab value on the first date for this ID (124).

    =XLOOKUP(1, ($A$2:$A$17=E2)*(LARGE($B$2:$B$17,COUNTIF($B$2:$B$17,">"&$F$2)+1)<=F2), $C$2:$C$17)

    The data is unsorted and is large, ~110,000 rows.

    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,112

    Re: XLOOKUP and dates with multiple criteria.

    Hi & welcome to the board.
    How about
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-13-2022
    Location
    Cardiff, Wales
    MS-Off Ver
    Microsoft 365 for Mac
    Posts
    3

    Re: XLOOKUP and dates with multiple criteria.

    Amazing. Thanks very much.
    Was working out what the formula did. Shouldn't the Sort Index be 2 even though your formula works?
    ie. =INDEX(SORT(FILTER(B2:C17,(A2:A17=E2)*(B2:B17<=F2)),2,-1),1,2)
    Only because I will have to use this formula on a much larger dataset with multiple columns.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,621

    Re: XLOOKUP and dates with multiple criteria.

    This is the difference:

    ID Clinic date
    A251527 17/09/2008


    =FILTER(B2:C17,(A2:A17=E2)*(B2:B17<=F2))
    13/06/2008 124
    16/06/2008 115
    18/06/2008 114
    23/06/2008 113
    24/06/2008 108
    24/06/2008 113
    12/08/2008 130

    =SORT(FILTER(B2:C17,(A2:A17=E2)*(B2:B17<=F2)),1,-1)
    12/08/2008 130
    24/06/2008 108
    24/06/2008 113
    23/06/2008 113
    18/06/2008 114
    16/06/2008 115
    13/06/2008 124

    =INDEX(SORT(FILTER(B2:C17,(A2:A17=E2)*(B2:B17<=F2)),1,-1),1,2)
    130

    =FILTER(B2:C17,(A2:A17=E2)*(B2:B17<=F2))
    13/06/2008 124
    16/06/2008 115
    18/06/2008 114
    23/06/2008 113
    24/06/2008 108
    24/06/2008 113
    12/08/2008 130

    =SORT(FILTER(B2:C17,(A2:A17=E2)*(B2:B17<=F2)),2,-1)
    12/08/2008 130
    13/06/2008 124
    16/06/2008 115
    18/06/2008 114
    23/06/2008 113
    24/06/2008 113
    24/06/2008 108

    =INDEX(SORT(FILTER(B2:C17,(A2:A17=E2)*(B2:B17<=F2)),2,-1),1,2)
    130
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,621

    Re: XLOOKUP and dates with multiple criteria.

    I think, if you play around with the dates, you'll get different results. The formula you have suggested will still return 130 because it is the largest number in the second column of the filtered array, regardless of the dates.

    For example, on row 10, change 18/08/2008 to 18/06/2008 and see what happens.

  6. #6
    Forum Expert wk9128's Avatar
    Join Date
    08-15-2020
    Location
    Australia
    MS-Off Ver
    365 V2403 and WPS V2022
    Posts
    3,493

    Re: XLOOKUP and dates with multiple criteria.

    Pls change xlookup to index+match

    Cell H2 formula

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


    OR array formula

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

  7. #7
    Registered User
    Join Date
    02-13-2022
    Location
    Cardiff, Wales
    MS-Off Ver
    Microsoft 365 for Mac
    Posts
    3

    Re: XLOOKUP and dates with multiple criteria.

    Thanks all for your help. I get it now.
    I think I'm correct in saying that: INDEX/SORT/FILTER works regardless of date order. INDEX/MATCH only works if in date order. That's important to know.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,621

    Re: XLOOKUP and dates with multiple criteria.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  9. #9
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,112

    Re: XLOOKUP and dates with multiple criteria.

    Shouldn't the Sort Index be 2 even though your formula works?
    Nope, it's sorting the dates from high to low, so that the most recent date is first & then the index function returns the first row from the sorted list.

    Glad to help & thanks for the feedback.

+ 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. Xlookup with multiple criteria
    By Mackay2m in forum Excel Formulas & Functions
    Replies: 21
    Last Post: 01-12-2022, 04:09 PM
  2. Xlookup return maximum value for multiple criteria
    By Excelforum2020 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-09-2021, 10:18 AM
  3. Replies: 5
    Last Post: 08-17-2021, 03:06 PM
  4. Help on XLOOKUP formula with multiple criteria
    By lyzas in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-22-2021, 05:06 AM
  5. Multiple criteria for XLOOKUP formula
    By mikehk in forum Excel General
    Replies: 1
    Last Post: 06-28-2021, 05:50 PM
  6. Replies: 3
    Last Post: 06-24-2021, 10:31 AM
  7. [SOLVED] XLOOKUP to return cell based on multiple criteria in single column
    By mikehay08 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-24-2021, 02:59 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