+ Reply to Thread
Results 1 to 20 of 20

Index and Match multiple rows - only returning top row

  1. #1
    Registered User
    Join Date
    07-21-2014
    Location
    England
    MS-Off Ver
    365
    Posts
    30

    Index and Match multiple rows - only returning top row

    Hi there,

    I'm using an Index and Match function to search a dataset and return various values based upon one horizontal value (i.e. column B), and one vertical value (row 2). [Very simplified version of data is shown in a picture below]

    The unique ID (i.e. column B) in some cases appears more than once in the dataset (highlighted in pink) and therefore has multiple rows in the dataset.

    When requesting a value for an ID with multiple rows, it only returns the value found in the first relevant row - in the example shown a "no" - see orange highlighted cells.

    However, what I need to do sometimes is overwrite that "no" with a "yes" if a yes is present in one of the other rows.

    Any ideas of how to do this most easily? Thanks for your help.

    Picture1.jpg
    Attached Images Attached Images

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,186

    Re: Index and Match multiple rows - only returning top row

    Are you still using Excel 2019?
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  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 2406
    Posts
    44,662

    Re: Index and Match multiple rows - only returning top row

    See if you can adapt this (I made a simpler sample, as we can NOT edit pictures of Excel files).

    =IF(ISNUMBER(MATCH(D4,A:A,0)),IF(SUM(--ISNUMBER(SEARCH("Yes",INDEX(B:B,AGGREGATE(15,6,ROW($A$4:$A$15)/($A$4:$A$15=D4),ROW(INDIRECT("1:"&COUNTIF(A:A,D4))))))))=1,"Yes","No"),"Not Present")
    Attached Files Attached Files
    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

  4. #4
    Registered User
    Join Date
    07-21-2014
    Location
    England
    MS-Off Ver
    365
    Posts
    30

    Re: Index and Match multiple rows - only returning top row

    Hi @AliGW - I'm using Office 365, so don't think I'd be limited to Office 2019.

  5. #5
    Registered User
    Join Date
    07-21-2014
    Location
    England
    MS-Off Ver
    365
    Posts
    30

    Re: Index and Match multiple rows - only returning top row

    Hi Glenn,

    Sorry rookie error, attaching a file this time. I did try to adapt the formula you kindly shared, but it wasn't working for me.

    Thanks for your help.

    Greg
    Attached Files Attached Files

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,186

    Re: Index and Match multiple rows - only returning top row

    Please update your forum profile to Office 365 without delay. Thanks.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,186

    Re: Index and Match multiple rows - only returning top row

    Clear ALL expected results, then in G4:

    =BYROW(F4:F12,LAMBDA(r,XLOOKUP(r,B4:B14,D4:D14)))
    Attached Files Attached Files

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,186

    Re: Index and Match multiple rows - only returning top row

    Or maybe this is what you want (returns the LAST entry for each 'person'):

    =BYROW(F4:F12,LAMBDA(r,TAKE(FILTER(D4:D14,B4:B14=r),-1)))
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    07-21-2014
    Location
    England
    MS-Off Ver
    365
    Posts
    30

    Re: Index and Match multiple rows - only returning top row

    Thank you@AliGW.

    Profiled now updated.

    The first solution isn't working for what I need sorry. For example in cell G5, that should be a Yes - as I'd want a 'Yes', if present in any row, to overwrite any other No's.

    The second solution - 'last entry' - wouldn't work for the larger 'real life' dataset as in some cases there might be three or more rows with the same unique ID.

    Any other thoughts - thank you!

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

    Re: Index and Match multiple rows - only returning top row

    Delete expected results... this returns the unique VALUES, and YES if YES is one of the possible answers.

    =LET(A,B4:B14,B,D4:D14,C,UNIQUE(A),D,BYROW(C,LAMBDA(x,IF(ISERROR(MATCH("Yes",FILTER(B,A=x),0)),"No","Yes"))),HSTACK(C,D))
    Attached Files Attached Files

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,186

    Re: Index and Match multiple rows - only returning top row

    So what needs to happen exactly for any unique ID? If there is ANY yes, return yes, and if not, return no - is that it?

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

    Re: Index and Match multiple rows - only returning top row

    Ali, that's my understanding of it.

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,186

    Re: Index and Match multiple rows - only returning top row

    Yes - I'm not bothering, since I saw your suggestion.

  14. #14
    Registered User
    Join Date
    07-21-2014
    Location
    England
    MS-Off Ver
    365
    Posts
    30

    Re: Index and Match multiple rows - only returning top row

    Thanks both for your time.

    Yep, that is the right understanding.

    The formula =LET(A,B4:B14,B,D4:D14,C,UNIQUE(A),D,BYROW(C,LAMBDA(x,IF(ISERROR(MATCH("Yes",FILTER(B,A=x),0)),"No","Yes"))),HSTACK(C,D)) does the job - but no idea how it works! haha.

    Probably a stupid question but I can't seem to 'select' the formula to try and adapt it for other files (?) I think I'm being stupid though.

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

    Re: Index and Match multiple rows - only returning top row

    I'm not really sure what you mean by "Select"... but if the setup is the same th eonly thing you need to change are the bits in RED:

    =LET(A,B4:B14,B,D4:D14,C,UNIQUE(A),D,BYROW(C,LAMBDA(x,IF(ISERROR(MATCH("Yes",FILTER(B,A=x),0)),"No","Yes"))),HSTACK(C,D))


    Excel does the rest. If that's the case...You're welcome. Thanks for letting us know that you got an answer.

    However, if the setup is different, post another sample file.




    Please take a moment and consider clicking the "Add Reputation" button at the foot of any of the posts of anyone who helped you reach a solution here today.

    Finally, if that takes care of your original question, please click on "Thread Tools" from the menu link (just above the first post in the thread) and mark this thread as SOLVED.

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

    Re: Index and Match multiple rows - only returning top row

    In case you're interested (but I wouldn't use it, as the O365 friendly version at Post 15 will be MUCH faster), this is how my original suggestion should have looked in your sample file.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    07-21-2014
    Location
    England
    MS-Off Ver
    365
    Posts
    30

    Re: Index and Match multiple rows - only returning top row

    Thanks Glenn. Yep happy to use the suggestion at Post 15.

    Just struggling to make the formula work to repeat the same task but for columns J and K in the sample file. I would just want column I, J and K all to refer to column H as opposed to having a repeated column H each time the formula is used. So wasn't sure which part to remove.
    Attached Files Attached Files

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

    Re: Index and Match multiple rows - only returning top row

    I'm not surprised that you got in a mess. So did I. I'd recommend a simpler approach:

    =UNIQUE(B4:B14)

    and this, copied ACROSS

    BYROW($H4#,LAMBDA(x,IF(ISERROR(MATCH("Yes",FILTER(D4:D14,$B$4:$B$14=x),0)),"No","Yes")))
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    07-21-2014
    Location
    England
    MS-Off Ver
    365
    Posts
    30

    Re: Index and Match multiple rows - only returning top row

    Sorry for the delayed reply Glenn.

    That works perfectly, thanks very much for your time and solution!

  20. #20
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,186

    Re: Index and Match multiple rows - only returning top row

    Here it is all in one:

    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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. Textjoin & index match returning multiple rows
    By jjqq in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-06-2022, 08:22 PM
  2. [SOLVED] Returning Multiple Rows of Data (VLOOKUP/INDEX MATCH)
    By aglasier in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-30-2017, 12:49 PM
  3. Returning multiple columns with INDEX/MATCH?
    By vudupins in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-16-2016, 03:10 PM
  4. [SOLVED] Two criteria Index Match on multiple sheets returning multiple values
    By Joak in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-21-2014, 10:03 AM
  5. [SOLVED] Index match with multiple criteria and returning last value
    By L.Steele in forum Excel General
    Replies: 2
    Last Post: 05-30-2012, 02:27 PM
  6. Returning multiple entries with INDEX and MATCH
    By jessea in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 08-04-2011, 02:50 PM
  7. Returning MULTIPLE values with Index and Match
    By Fly in forum Excel General
    Replies: 1
    Last Post: 06-01-2006, 12:55 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