+ Reply to Thread
Results 1 to 4 of 4

how to return the second occurence with index function ?

  1. #1
    Registered User
    Join Date
    12-28-2009
    Location
    Sydney,Australia
    MS-Off Ver
    Excel 2003
    Posts
    31

    how to return the second occurence with index function ?

    hello,

    I am trying to return the quantity for the second occurrence of apple from a table using

    =INDEX(A2:C6,SMALL(IF(A2:C6="apple",ROW(A2:C6)-ROW(A2)+1,ROW(C6)+1),2),2)

    the description says that it returns the quantity for the second occurrence of apple,

    but if i look at it this way...

    ROW(A2:C6) = 2

    ROW(A2:C6)-ROW(A2)+1 = 2-2 +1 =1

    Then

    IF(A2:C6="apple",ROW(A2:C6)-ROW(A2)+1,ROW(C6)+1)

    =

    IF(A2:C6="apple",1, 7)

    and since apple is contained within A2:C6

    IF(A2:C6="apple",1, 7) = 1

    so

    SMALL(IF(A2:C6="apple",ROW(A2:C6)-ROW(A2)+1,ROW(C6)+1),2),2)

    =

    SMALL(1,2)

    = 1

    Then

    INDEX(A2:C6,1 ,2) would return the value from the first row and the second column, but the quantity for the second occurrence of apple should be in row 4 and column 2 .
    Attached Images Attached Images

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: how to return the second occurence with index function ?

    HI MasterInex,

    Instead on image, upload an excel workbook and mention you expected output. Thanks.

    Regards,
    DILIPandey
    <click on below * if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  3. #3
    Valued Forum Contributor
    Join Date
    10-29-2012
    Location
    Mojokerto,Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    554

    Re: how to return the second occurence with index function ?

    This may be simpler than yours
    (array formula)
    =INDEX(B2:B6;SMALL(IF(A2:A6="apple";C2:C6);2))

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: how to return the second occurence with index function ?

    Try it like this...

    Array entered**:

    =INDEX(B:B,SMALL(IF(A2:A6="apple",ROW(A2:A6)),2))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

+ 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