+ Reply to Thread
Results 1 to 27 of 27

How to find most and second most common entry from alpha list

  1. #1
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    How to find most and second most common entry from alpha list

    Can someone help me with trying to determine what the most common entry would be from a list. For example,

    human
    human
    elf
    elf
    elf
    halfling

    The most common is elf, the second most common is human.

    Also, say I wanted to add a level to each entry and depending on the level of the entry would resolve the most common.

    human 7
    human 3
    elf 2
    elf 2
    elf 2
    halfling 7

    In this example, human would be most (as 7+3) and halfling would be second most (7).

    Cheers,

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

    Re: How to find most and second most common entry from alpha list

    Joah,

    Attached is an example workbook based on the criteria you described. It contains both scenarios from your original post.

    To get the nth most common without a numeric value, in cell D3 and copied down is this formula:
    Please Login or Register  to view this content.

    To get the nth most common with a numeric value, in cell J3 and copied down is this formula:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Hope that helps,
    ~tigeravatar

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

  3. #3
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    wow I certainly appreciate this entry, thank you.

    Working with the first part of your attachment, if I change certain values say from human to halfling, where it would be most common halflings, it returns human.

    Also I don't understand the reference to $d$2:d2 as this is blank in your spreadsheet.

    Cheers,

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

    Re: How to find most and second most common entry from alpha list

    Joah,

    I am unable to duplicate that issue. What is the list of items that is causing an incorrect result?

  5. #5
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    wow I certainly appreciate this entry, thank you.

    How would I make the second entry most common not be like the first common as say if I had:

    elf
    elf
    elf
    halfling
    halfling
    halfling

    then the first most common would be elf and the second most common would be elf (I suppose based upon the initial order of entry) but how could we make the second most common halfling and not the first most common (ever).

    Cheers,

  6. #6
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: How to find most and second most common entry from alpha list

    Joah, if you change values, be sure that calculation is set to Automatic. (Excel Options > Formulas)

  7. #7
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    sorry for the message lag heh heh

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

    Re: How to find most and second most common entry from alpha list

    Joah,

    Ah, I see. Attached is version 2, with corrected formulas for both methods to prevent that when there are exactly the same number of an entry.

    Method 1 (no values), in cell D3 and copied down:
    Please Login or Register  to view this content.
    Method 2 (with values), in cell J3 and copied down:
    Please Login or Register  to view this content.

    The reference to $d$2:d2 is there to advance to the next nth item in the list. It doesn't have to be a blank cell in D2, it could be a header, or any text you'd like. The reference grows as the formula is copied down. So in cell D4, that reference becomes $d$2:d3. Again, this is solely to advance to the next nth item.
    Attached Files Attached Files
    Last edited by tigeravatar; 06-19-2012 at 05:14 PM. Reason: Added code tags to second formula, corrected typos

  9. #9
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    Actually I'm just realizing that maybe this is a bit more complicated than I originally thought.

    As we have primary and secondary races, the primary race *can be composed of the same as secondary race if all values are equal otherwise the primary race is different than the secondary race if the values are different.

    So
    elf
    elf
    elf
    elf
    would be primary elf, secondary elf

    but
    elf
    elf
    human
    human
    would be primary elf, secondary human

    Cheers,

  10. #10
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    btw thanks for taking the time to help me, I just love the internet that it can connect us like this,

    Cheers,

  11. #11
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    ok almost there, if primary and secondary are the same then secondary becomes n/a so I just need to put a if n/a then same as primary?

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

    Re: How to find most and second most common entry from alpha list

    Yes. So the formula in cell D3 would become:
    =IFERROR(existing formula,D2)

    Then copy down.

  13. #13
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    Nicely done, I am just loving this, so much fun,

    Cheers,

  14. #14
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    I'm still not clear with what is happening at $d$2:d2 and $d$3:d3

  15. #15
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    =IFERROR(INDEX($C$4:$C$28,MATCH(1,INDEX((COUNTIF($C$4:$C$28,$C$4:$C$28)=LARGE(INDEX(COUNTIF($C$4:$C$28,$C$4:$C$28),),1+SUMPRODUCT(COUNTIF($C$4:$C$28,$C$29:C30))))*(COUNTIF($C$29:C30,$C$4:$C$28)=0),),0)),C30)

    this returns a 0 if all values are the same, maybe i need to replace a 0 with c30, ah, now I'm becoming lazybrain, heh heh

    Cheers,

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

    Re: How to find most and second most common entry from alpha list

    Alright, that range reference is used in this function: COUNTIF($A$3:$A$8,$D$2:D2)

    The $ symbols create an abolute reference, so as the formula is copied from one cell to another, the absolute reference won't change. So as the formula is copied down, the reference becomes:
    $D$2:D3
    $D$2:D4
    etc

    In this case, it only gets copied down once.

    What that function actually does, is count the number of occurrences within a cell range. The cell range is the first argument, $A$3:$A$8. What it's looking for so that it count the occurrences is the second argument, $D$2:D2.
    D2 is blank, so CountIf returns a 0. That number is added to 1 (1+0=1) to produce the k reference for the Large() function which is called earlier.
    When the formula is copied down, it counts all occurrences of both D2 and D3. D3 contains the formula's first result, so in this case it would be elf, and there are 3 occurrences of elf. So now it is 1+0+3=4. So now the Large function gets the 4th entry, which is fed to the rest of the function to produce the next result.

    I'm not sure if that helps, but that's what that reference is there for, to advance to the next nth value ignoring duplicates.

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

    Re: How to find most and second most common entry from alpha list

    That formula is correct, and is returning a 0 because you have 1 or more blank cells in C4:C28. Here's an updated formula using the ranges provided that will prevent the formula from looking at blank cells. This should go in C30 and get copied down:
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    Yeah, no matter what value I place in the last , be it c30, c29, 1, whatever, it always comes up 0.

  19. #19
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    You just replied in the last 30 seconds didn't you,

  20. #20
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    k let me try this, thanks,

  21. #21
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    k now it is function right when both primary and secondary are the same, but, heh heh, but yeah that's it. If I change the values of primary and secondary they are still the same.

  22. #22
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    btw thanks again for all your help, I am learning this stuff and I've already learned so much from this community.

    Cheers,

  23. #23
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    k I didn't read all of your post, I just jumped to the copy and paste. Feels like I'm an astronaut floating above the earth right about now. I need to place the last argument in cell 30. (Meanwhile my son is after me to play Borderlands wit me ...)

  24. #24
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    Well, that's it I'm out of time, must play Borderlands.

    Cheers,

  25. #25
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    =IFERROR(INDEX($C$4:$C$28,MATCH(1,INDEX((COUNTIF($C$4:$C$28,$C$4:$C$28)=LARGE(INDEX(COUNTIF($C$4:$C$28,$C$4:$C$28),),1+SUMPRODUCT(COUNTIF($C$4:$C$28,$C$29:C29))))*(COUNTIF($C$29:C29,$C$4:$C$28)=0)*($C$4:$C$28<>""),),0)),C29)

    got it to work if I change c29 to c30, dunno why but man, this string is disturbingly long for my sight taking breaks is key.

    Cheers,

  26. #26
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    365
    Posts
    2,243

    Re: How to find most and second most common entry from alpha list

    Consider A3 to down are entries,

    D3 with CTRL+SHIFT+ENTER, then copy down.

    Please Login or Register  to view this content.
    Adjust the range.

    This wouldn't return single entries
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  27. #27
    Forum Contributor
    Join Date
    06-11-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: How to find most and second most common entry from alpha list

    Yep, thanks for the angle,

    Cheers,

+ 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