+ Reply to Thread
Results 1 to 31 of 31

find 2nd instance of a duplicated value in an index/match formula?

  1. #1
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    find 2nd instance of a duplicated value in an index/match formula?

    Hey all, I am using the following formula
    =IFERROR(INDEX(BO$14988:BO$29986,MATCH(M5931,AT$14988:AT$29986,0)),"")

    to return release names of songs that have been released on compilations.

    We recompile songs up to 3 times after they have been originally released, to give them more opportunities to be found by music buyers.

    If I have recompiled a song twice already, my formula above only returns the album name for the first compilation.
    I need to also find the second compilation, to prevent releasing a song on a later volume of a compilation brand it has already been out on.

    Can anyone recommend a way of doing this?
    as you can see I am working with about 30,000 songs/lines of data, so it needs to be a cpu efficient method.

    thanks in advance!

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Hi bobbo,

    Can you upload a sample workbook indicating your expected results ? thanks


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

  3. #3
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Hi there, sorry for the delay, here is an example of where I am at.

    Ok so in the example workbook, row 1 is my pallette, the area where i grab my songs from to recompile.
    It has a typical line of data i'm working with, from column A to AF.
    much of the data is deleted for privacy reasons.

    rows 3 to 9 are where I paste finished compilations.

    Cell AD1 shows me that this particular song, has already been recompiled twice.
    It triggers conditional formatting in A1.

    Cell AE1 shows me the compilation name, from the first time it was recompiled.

    WHAT I NEED is for cell AF1 to show the compilation name, from the SECOND time it was recompiled.
    the result should be House Keys (A#m) world Edition 1


    I'm stumped as to how to do it! thanks all for any suggestions!
    Attached Files Attached Files

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Okay..use below formula which need to be entered with key combination: ctrl shift enter

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


    example.xlsx

    Regards,
    DILIPandey
    <click on below * if this helps>

  5. #5
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Hey mate, thanks very much for assisting me!

    I pasted your formula into AF1 of the example workbook and it brought back #value!

  6. #6
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,361

    Re: find 2nd instance of a duplicated value in an index/match formula?

    since dilip is offline and you are waiting.
    try to hit ctrl + shift + enter not just enter you'll notice the curly braces around the formula {formula} if done correctly
    I think people forget the word "THANK YOU!!!!" Do you still know it???

    There is a little star ( ADD REPUTATION ) below those person who helped you. Click it to say your "PRIVATE APPRECIATION TO THEIR EFFORT ON THEIR CONTRIBUTIONS "

    Regards,
    Vladimir

  7. #7
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    gotcha, yes this has worked Thanks guys.

    I haven't understood what CTRL SHIFT enter does, ill google it now.

    I would love it the formula was explained to me tho please?
    I understand the index/match approach, but this is different. Its index, max, if, row.
    Thanks guys

  8. #8
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Oh right so they are array formulas... I have heard that I need to stay away from them as they are very CPU hungry.
    I have 14000 lines of data that this needs to be applied to... I'm expecting trouble! Ill try it.

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Quote Originally Posted by Bobbo Jones View Post
    I haven't understood what CTRL SHIFT enter does, ill google it now.
    See this:

    http://www.cpearson.com/Excel/ArrayFormulas.aspx
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  10. #10
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Ok so far this may be too cpu intensive, I have my spreadsheet set to manually calculate, but after hitting calculate it took 5 minutes to calculate 2000 records. it seems to be working smoothly once finished, ill persevere a bit more before trying it with all 14000

    2 things about this formula.

    It returns a result for the 1st time a track is used, as well as the 2nd. (will it for the 3rd?)
    this is messy. If I already have an answer for the 1st, how can this formula return a 0 in the 2nd column instead of repeating the answer?

    Also, how can this return an empty cell instead of a 0?

    thanks!
    Evan
    Last edited by Bobbo Jones; 06-13-2013 at 09:48 PM.

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    What formula are you using?

  12. #12
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    the one provided in AF and my own one which i showed in the original question above in column AE.

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Well, I was hoping you would post the formula.

    If you're using an array formula then DON'T use entire columns as range references. Use smaller specific ranges.

  14. #14
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    here are the formulas again.

    In AE1 =IFERROR(INDEX(BO$14988:BO$29986,MATCH(M5931,AT$14988:AT$29986,0)),"")

    in AF1 =INDEX($AJ:$AJ,MAX(IF($AT:$AT=$M$1,ROW($AT:$AT),""))) with ctrl shift enter

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Quote Originally Posted by Bobbo Jones View Post
    in AF1 =INDEX($AJ:$AJ,MAX(IF($AT:$AT=$M$1,ROW($AT:$AT),""))) with ctrl shift enter
    OK, that's the formula that's causing the problem.

    Do not use entire columns as range references. Use smaller specific ranges.

  16. #16
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    OK I have just realised that the formula provided by dilipandey will NOT work.

    This is because it returns the LAST instance of $m$1 NOT the 2nd.

    I need the 2nd instance ONLY

  17. #17
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    apologies for overusing caps.

  18. #18
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Ill try this Tony and reply again thanks!

  19. #19
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    HI Tony I've tried this, Im not sure which problem this is meant to be fixing apart from reducing CPU load.

    anyway, ive done it, however it only works when I leave the Index Array as the entire column

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Quote Originally Posted by Bobbo Jones View Post
    OK I have just realised that the formula provided by dilipandey will NOT work.

    This is because it returns the LAST instance of $m$1 NOT the 2nd.

    I need the 2nd instance ONLY
    For the 2nd instance use something like this array formula**:

    =INDEX($AJ:$AJ,SMALL(IF($AT$2:$AT$100=$M$1,ROW($AT$2:$AT$100)),2))

    Adjust the ranges to suit.

    Note that I am not using entire columns as range references in the IF function.

    ** 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.

  21. #21
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Brilliant thanks for the alternative formula, I will try this now.

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    I'm logging off for the day. I'll check back tomorrow to see how you made out.

  23. #23
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: find 2nd instance of a duplicated value in an index/match formula?

    @Tony:
    i have always wanted to ask you this, but you have chosen not to receive PMs. is there a source where someone has tested or a way to find out if referring to the whole column like you suggested outside the IF portion would be faster than this?
    =INDEX($AJ$2:$AJ$100,SMALL(IF($AT$2:$AT$100=$M$1,ROW($AT$2:$AT$100)-ROW($AJ$2)+1),2))

    i also played around with non-array ways of doing, but never got to verify which ways are faster

    hope the moderators are ok with me asking this here as this is related to OP's performance issue

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  24. #24
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Hi Benishiryo Thanks for asking this, it would be relevant to my project as well.

    Tony I have applied your new formula, and it seems to be working well.
    How to I remove the #NUM! result though? Is there a way to make it return a 0 or an empty cell?

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    I have tested those variations of the formulas which is what led me to start referring to the entire column in the INDEX function.

    I used to do it the same way as everyone else:

    =INDEX($AJ$2:$AJ$100,SMALL(IF($AT$2:$AT$100=$M$1,ROW($AT$2:$AT$100)-ROW($AJ$2)+1),n))

    But then I got curious and started experimenting.

    If you index the entire column there is no need to calculate an "offset correction". In my testing, indexing the entire column had no negative effect on performance.

    Try this...

    If you don't like indexing the entire column then at least move the offset correction outside the SMALL function.

    Using this syntax:

    =INDEX($AJ$2:$AJ$100,SMALL(IF($AT$2:$AT$100=$M$1,ROW($AT$2:$AT$100)-ROW($AJ$2)+1),n))

    You calculate an ARRAY of offset corrections:

    ROW($AT$2:$AT$100)-ROW($AJ$2)+1

    That's not necessary. If you put the offset correction outside the SMALL function then you calculate just a SINGLE offset correction:

    =INDEX($AJ$2:$AJ$100,SMALL(IF($AT$2:$AT$100=$M$1,ROW($AT$2:$AT$100)),n)-ROW($AJ$2)+1)

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Wrap the formula inside the IFERROR function:

    To return a blank:

    =IFERROR(INDEX($AJ:$AJ,SMALL(IF($AT$2:$AT$100=$M$1,ROW($AT$2:$AT$100)),2)),"")

    To return 0:

    =IFERROR(INDEX($AJ:$AJ,SMALL(IF($AT$2:$AT$100=$M$1,ROW($AT$2:$AT$100)),2)),0)

    Still array entered.

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Quote Originally Posted by benishiryo View Post
    @Tony:
    i have always wanted to ask you this, but you have chosen not to receive PMs.
    From past experience at other forums...

    I was getting too many PMs asking for help so I had to disable PMs.

  28. #28
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    Thanks Tony!~ I should have remembered the if error thing, i learnt it last week! gah, my mind is not built for this stuff..

    last question?

    I notice I can simply change the number at the end of the formula to 1, and it could work in my AE column as well.

    Which formula do you think would work best in terms of cpu and ram efficiency?

    my original formula in AE1 or yours in AF1 which can be slightly tweaked to go in AE1?

    thanks

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    If you're wanting to find the 1st instance then the INDEX/MATCH version is more efficient.

  30. #30
    Registered User
    Join Date
    10-29-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Enterprise 2007
    Posts
    51

    Re: find 2nd instance of a duplicated value in an index/match formula?

    OK thanks mate

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

    Re: find 2nd instance of a duplicated value in an index/match formula?

    You're welcome!

+ 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