+ Reply to Thread
Results 1 to 13 of 13

Array Formula to extract 5 Smallest Records Matching Multiple Criteria

  1. #1
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    Hello guys,

    I am stuck with this index array formula, hope anyone can help me out.

    Please see attached file where I need to extract (ProductID into J2:J6) the smallest 5 records based on amount column that match criteria values in Column H & also in Column D the amount need to be greater than 0.
    Attached Files Attached Files
    Last edited by ibuhary; 03-09-2016 at 10:21 AM.

  2. #2
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    Sorry guys forgot the attachment earlier. Now its there.

  3. #3
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    Enter array formula in J2 and copy across to Col L and then down
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Enter array formula in M2 and copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    ***Array formula must be entered by using key combination of CTRL+SHIFT+ENTER and not just ENTER


    v H I J K L M
    1 MATCH ProductID Description Class Amount
    2 B 0100102 Name B 4500
    3 0100105 Name B 3000
    4 0100110 Name B 500
    5 0100113 Name B 2500
    6 0100118 Name B
    7
    8
    9
    Attached Files Attached Files
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  4. #4
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    I am afraid, you have not matched multiple items in Column H.
    In my file I have mentioned that you need to match items in H2:H3 (i.e B & C).

  5. #5
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    Quote Originally Posted by ibuhary View Post
    I am afraid, you have not matched multiple items in Column H.
    In my file I have mentioned that you need to match items in H2:H3 (i.e B & C).
    Can you show what the final outcome should look like?

  6. #6
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    ProductID Description Class Amount
    0100110 Name B 500
    0100116 Name C 1000
    0100108 Name C 1500
    0100113 Name B 2500
    0100105 Name B 3000

  7. #7
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    Try this one

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

    ***Array formula must be entered by using key combination of CTRL+SHIFT+ENTER and not just ENTER

    Copy across all the way to column M and then down

    v H I J K L M
    1 MATCH ProductID Description Class Amount
    2 B 0100105 Name B 3000
    3 C 0100108 Name C 1500
    4 0100110 Name B 500
    5 0100113 Name B 2500
    6 0100116 Name C 1000
    7
    8
    9
    Last edited by AlKey; 03-10-2016 at 10:56 AM.

  8. #8
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    few points for your note as follows:
    1. I don't see the smallest record (in terms of Amount on Top), i think instead you have sorted out based on product ID. I need the order based on "Amount" column; and
    2. What if I have more than two records in Column H to match with, e.g. 10 items??? There should be some way to refer to them as H2:H11 rather than building the formula by referring to each one of them individually.

    Please note that the example file is only an extract from my database. Actually my database runs for over 200 thousand lines with categories over 20, out of which I am trying to extract smallest 100 records that match around 10 categories for those amounts are not equal zero.

  9. #9
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    Here is another way with a helper column ( col E )

    1. Enter formula below in E2 and copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    now you can enter as many class values in Col H as you want and the range will adjust automatically.

    2. for Amounts enter formula in M2 and copy down

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


    3. now enter this formula in J2 and copy across to L2 and down
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Please see attached workbook.
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor
    Join Date
    05-11-2013
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    586

    Re: Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    I have converted the data range to a table and used the filters.
    This gives you the bottom 6 - see attached.
    Will this work for you?

    peterrc
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    I am sorry, but I am looking for extracting the data via formula. I am unable to apply sorting or filter or helper columns to the database.
    Last edited by ibuhary; 03-13-2016 at 12:52 PM.

  12. #12
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    Thanks a lot guys, I managed to do it with the following array function:

    {=INDEX($A$2:$A$21,MATCH(SMALL(($D$2:$D$21)*--(IFERROR(MATCH($C$2:$C$21,$H$2:$H$3,0),0)>0)*($D$2:$D$21>0),COUNTA($D$2:$D$21)-SUMPRODUCT(--((IFERROR(MATCH($C$2:$C$21,$H$2:$H$3,0),0))>0)*--($D$2:$D$21>0))+ROW(J2)-ROW($J$2)+1),$D$2:$D$21,0),1)}

    It works find provided there are no duplicate values in amount column.

  13. #13
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Array Formula to extract 5 Smallest Records Matching Multiple Criteria

    Quote Originally Posted by ibuhary View Post
    Thanks a lot guys, I managed to do it with the following array function:

    {=INDEX($A$2:$A$21,MATCH(SMALL(($D$2:$D$21)*--(IFERROR(MATCH($C$2:$C$21,$H$2:$H$3,0),0)>0)*($D$2:$D$21>0),COUNTA($D$2:$D$21)-SUMPRODUCT(--((IFERROR(MATCH($C$2:$C$21,$H$2:$H$3,0),0))>0)*--($D$2:$D$21>0))+ROW(J2)-ROW($J$2)+1),$D$2:$D$21,0),1)}

    It works find provided there are no duplicate values in amount column.
    " I need the order based on "Amount""

    And this is precisely why your approach will not work. Duplicate values.

+ 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: 7
    Last Post: 06-28-2015, 10:47 AM
  2. [SOLVED] SUMIFS formula that takes first seven of matching criteria from an array
    By Samuel_j in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-24-2015, 05:08 AM
  3. Pulling records matching two criteria and inserting those records into an existing list
    By desertfx41 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-14-2014, 02:00 PM
  4. MS query needs to extract records with matching values
    By knuckleheadmike in forum Excel General
    Replies: 0
    Last Post: 05-16-2014, 10:35 PM
  5. Formula to Compare and Copy to New Sheet Multiple Matching Records
    By virgIris13 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-11-2013, 03:00 PM
  6. [SOLVED] return multiple records matching multiple criteria
    By Karthik in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-22-2006, 12:45 PM
  7. Extract multiple records matching criteria from list
    By William DeLeo in forum Excel Formulas & Functions
    Replies: 56
    Last Post: 09-06-2005, 12:05 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