+ Reply to Thread
Results 1 to 19 of 19

Array formula - index and match with multiple statements

  1. #1
    Registered User
    Join Date
    05-05-2010
    Location
    Maidenhead, England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Array formula - index and match with multiple statements

    Hi all,

    I am trying to understand how to use index and match in an array formula. Probably easiest to take a look at my example sheet. For some reason, the first result is working, but the others aren't. Can anyone explain why please?

    Alternatively, here is a screenshot.

    05062013154410.png

    The formula I have tried is: =INDEX($E$3:$E$11,MATCH(1,IF($A$3:$A$11=G3,IF($B$3:$B$11=H3,IF($C$3:$C$11=I3,IF($D$3:$D$11=MEDIAN(J3,K3,$D$3:$D$11),1,0) ,0),0),0),0))

    confirmed with ctrl shift enter.

    Many thanks
    Paul
    Attached Files Attached Files

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Array formula - index and match with multiple statements

    Give a try to ths ARRAY formula.

    =INDEX(E$3:E$11,SMALL(IF(($A$3:$A$11=G3)*($B$3:$B$11=H3)*($C$3:$C$11=I3)*($D$3:$D$11>=J3)*($D$3:$D$11<=K3),ROW(E$3:E$11)-2),ROW($E$1)))
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,705

    Re: Array formula - index and match with multiple statements

    Not sure what you are trying to do with the MEDIAN term, but presumably you are looking for the date being between the start and end dates (J and K). If so, try this array* formula in L3:

    =INDEX($E$3:$E$11,MATCH(1,IF(($A$3:$A$11=G3)*($B$3:$B$11=H3)*($C$3:$C$11=I3)*($D$3:$D$11>=J3)*($D$3:$D$11<=K3),1,0),0))

    *Confirm with Ctrl-Shift-Enter, then copy down.

    Hope this helps.

    Pete

  4. #4
    Registered User
    Join Date
    05-05-2010
    Location
    Maidenhead, England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Array formula - index and match with multiple statements

    That works, many thanks.

    Could you possibly explain it to me please? I am trying to use this spreadsheet as a lead up to the real one I need to do which compares multiple conditions for 11,300 rows to 9000 rows.

    I was hoping I could fix my formula above in an effort to understand how it works.


    edit: Pete_UK, yes, the median term works well for finding if a date is between 2 dates, so i was trying to use that
    Last edited by A[L]C; 06-05-2013 at 11:21 AM.

  5. #5
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Array formula - index and match with multiple statements

    =INDEX(E$3:E$11,SMALL(IF(($A$3:$A$11=G3)*($B$3:$B$11=H3)*($C$3:$C$11=I3)*($D$3:$D$11>=J3)*($D$3:$D$11<=K3),ROW(E$3:E$11)-2),ROW($E$1)))

    The INDEX part of the formula you know how it works,

    The small(if( part of the formula describe the conditions..

    The ROW part ..ROW(E$3:E$11)-2), actually "says" in which row the formula must start searcing. As your Data start in row 3, formula is .ROW(E$3:E$11)-2). If your data start in row 25..formula should be ...ROW(E$3:E$11)-24).

    ROW($E$1))) This locked by $ symbol, means that we need just one result for eatch case..

    Hope this helps you.

  6. #6
    Registered User
    Join Date
    05-05-2010
    Location
    Maidenhead, England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Array formula - index and match with multiple statements

    Thanks for that. What does the * mean in between the statements?

    edit: oh its just multiplied? so 1*1*1*1*1
    Last edited by A[L]C; 06-05-2013 at 11:39 AM.

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,705

    Re: Array formula - index and match with multiple statements

    That is equivalent to AND for arrays. You can read it as Column A = G3 AND Column B = H3 AND Column C = I3 ... and so on.

    NOTE: If you extend your ranges to 11,000+ rows, then the array formulae will take a considerable time to calculate.

    Hope this helps.

    Pete

  8. #8
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Array formula - index and match with multiple statements

    In fact(in this formula), * sign, replaces the AND function...

    So if( $A$3:$A$11=G3)AND($B$3:$B$11=H3)AND($C$3:$C$11=I3)AND........

  9. #9
    Registered User
    Join Date
    05-05-2010
    Location
    Maidenhead, England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Array formula - index and match with multiple statements

    Ahh ok, that makes more sense, thanks a lot. Better than the nested if's that's for sure.

    Pete, yeah, its certainly not ideal but it's a work around until we can get a better solution (its a product of multiple database tables). Hopefully my laptop won't take too long (core i7 3610-qm, 16gb ram, ssd). I will export values only before sending to others, unless you can think of a better way to do a multiple lookup without helper columns in excel?

  10. #10
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Array formula - index and match with multiple statements

    As an alternative, here's a slightly different approach, doesn't require Ctrl+Shift+Enter:
    =INDEX($E$3:$E$11,MATCH(1,INDEX(($A$3:$A$11&$B$3:$B$11&$C$3:$C$11=G3&H3&I3)*($D$3:$D$11>=J3)*($D$3:$D$11<=K3),),0))
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  11. #11
    Registered User
    Join Date
    05-05-2010
    Location
    Maidenhead, England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Array formula - index and match with multiple statements

    Woah, so many ways to skin a cat! Thanks. Confused between the difference of the array formula and this one now.

    Could anyone explain the differences?

  12. #12
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Array formula - index and match with multiple statements

    I have a rule that says:

    "If you have a not ARRAY formula(a regular formula) that works for you, then for sure is the best way to go on. Forget the Array formula"

  13. #13
    Registered User
    Join Date
    05-05-2010
    Location
    Maidenhead, England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Array formula - index and match with multiple statements

    Could someone explain how it (the regular formula) works please? :D

    The last part is ok, but how does ($A$3:$A$11&$B$3:$B$11&$C$3:$C$11=G3&H3&I3 work?

  14. #14
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Array formula - index and match with multiple statements

    Mine is basically an array formula (it calculates like one), it just doesn't need to be entered with ctrl+shift+enter. I basically used an extra INDEX() function to do the array portion automatically so that you don't have to tell Excel it's an array formula.

    Also instead of (range1=condition1)*(range2=condition2)*... I used this format: (range1&range2=condition1&condition2)
    Think of those two formats as being interchangeable (the same thing written differently).

    Other than those minor changes, its basically the same formula proposed earlier by Fotis and Pete

  15. #15
    Registered User
    Join Date
    05-05-2010
    Location
    Maidenhead, England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Array formula - index and match with multiple statements

    Thank you all very much. I am starting to grasp it :D

  16. #16
    Registered User
    Join Date
    05-05-2010
    Location
    Maidenhead, England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Array formula - index and match with multiple statements

    Uploading my example spreadsheet in case it helps other people. It includes all examples given in this thread.

    Thanks again to everyone.
    Attached Files Attached Files

  17. #17
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Array formula - index and match with multiple statements

    Very nice gesture.

    We thank you for that.

  18. #18
    Registered User
    Join Date
    05-05-2010
    Location
    Maidenhead, England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Array formula - index and match with multiple statements

    No problem. For me, the last column is the easiest to maintain

  19. #19
    Registered User
    Join Date
    05-05-2010
    Location
    Maidenhead, England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Array formula - index and match with multiple statements

    Just to note, on a large dataset (12,000 compared to 9,000), multiple vlookups with helper columns is a lot quicker to run than index and match.

    CPU has been maxed out at 100% on all 8 cores, memory usage at 1gb, for about 20 minutes so far! The vlookups calculate in about 2 minutes. So Pete_UK, you were totally right! (although I am using the non array formula)


    edit: 25 minutes so far, and it's on 20% calculating
    Last edited by A[L]C; 06-06-2013 at 11:24 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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