+ Reply to Thread
Results 1 to 13 of 13

Using Mode to find the most popular values. Not working.

  1. #1
    Registered User
    Join Date
    03-04-2011
    Location
    Fremont, CA
    MS-Off Ver
    Excel 2008 for Mac
    Posts
    31

    Using Mode to find the most popular values. Not working.

    I need to find the most popular medication codes in a range of data.

    I'm trying to use this formula:
    =IF(COUNTA(S$1:AI$1306)<10,0,INDEX(S$1:AI$1306,MODE(MATCH(S1$1:AI$1306,S$1:AI$1306,0)+{0,0})))

    which, up until now, when used as an array, has been listing the most popular values within a column in succession

    but it's giving me an #N/A value. I have three hypotheses:

    1) It's because #N/A values exist in that range
    So I did a find and replace to change all the #N/A values to a fake med code.
    That didn't fix the problem
    2) It's because there's these "." to indicate blank data (no med codes) in this range.
    So, I did a find and replace to change all the "." to a fake med code, but that didn't fix the problem either.
    3) It's because I'm using this formula on a range of data, rather than simply a column.
    I don't know how plausible this is. And It'd be a lot of work to test this one.

    So I thought I'd throw it out there, with the hope that you guys might have something to suggest. All suggestions are welcome and appreciated.

    Thank you.
    Last edited by adhamija; 03-04-2011 at 01:55 PM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using Mode to find the most popular values. Not working.

    Quote Originally Posted by adhamija
    =IF(COUNTA(S$1:AI$1306)<10,0,INDEX(S$1:AI$1306,MODE(MATCH(S1$1:AI$1306,S$1:AI$1306,0)+{0,0})))

    up until now, when used as an array, has been listing the most popular values within a column in succession
    I confess I'm slightly confused by the above assertion given MATCH works with vectors rather than matrices.

    Could you post a sample to illustrate what you're trying to achieve ?

  3. #3
    Registered User
    Join Date
    03-04-2011
    Location
    Fremont, CA
    MS-Off Ver
    Excel 2008 for Mac
    Posts
    31

    Re: Using Mode to find the most popular values. Not working.

    Here's an example:


    ID# Rx 1 Rx 2 Rx 3 Rx 4
    1900 GBN GJK . .
    1901 NTO GBN GJK .
    1902 #N/A #N/A #N/A #N/A
    1903 GBN . . .

    I want to find the most popular medcodes in this range, which, in this case, would ideally go like this:

    GBN
    GJK
    NTO


    Thank you. Hope this clarifies it a little bit

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using Mode to find the most popular values. Not working.

    A formula based approach will be very inefficient and most likely Volatile
    given use of XL2003 the options open to you are further restricted

    I would suggest you consider using a User Defined Function (VBA) - is that viable in your environment ?

  5. #5
    Registered User
    Join Date
    03-04-2011
    Location
    Fremont, CA
    MS-Off Ver
    Excel 2008 for Mac
    Posts
    31

    Re: Using Mode to find the most popular values. Not working.

    im not too familiar with VBA, but if you could walk me through it, that'd be great.I'm not exactly sure what would make it not viable. But I'll say it is.


    Thank you.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using Mode to find the most popular values. Not working.

    The below is adapted from a post on a not too dissimilar questions asked a week or so ago: http://www.excelforum.com/excel-work...ing-words.html

    Though the above thread and yours vary the code below should suffice (if a little over engineered for this particular query)

    Please Login or Register  to view this content.
    Attached is a working example - modifying inputs (Yellow) should cause results (Green) to update accordingly.

    Medium Security expected - "Enable Macros" on prompt - you can modify the output as necessary of course.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    03-04-2011
    Location
    Fremont, CA
    MS-Off Ver
    Excel 2008 for Mac
    Posts
    31

    Re: Using Mode to find the most popular values. Not working.

    Just realized that Excel 2008 for Mac does not support Visual basic editor. Also, when I tried to open the file you attached, it gives me the message Visual Basic macros cannot be opened in Excel 2008. What do you suggest?

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using Mode to find the most popular values. Not working.

    Other than updating your profile to indicate use of 2008 you mean

    Yes, no VBA support in 2008 unfortunately: remedied in 2011 thankfully.

    Formula wise - given use of XL2008 I will have a think... whatever people come up with you should note it won't be trivial and will be hideously inefficient unless you consider use of helper/intermediate matrix (COUNTIF etc)

    If you are able to revert to a vector you should - you can then just use a Pivot Table.

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using Mode to find the most popular values. Not working.

    In terms of single cell formulae / no helpers - attached is one approach.

    As mentioned / repeated previously the attached approach is is non-trivial, inefficient & volatile.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    03-04-2011
    Location
    Fremont, CA
    MS-Off Ver
    Excel 2008 for Mac
    Posts
    31

    Re: Using Mode to find the most popular values. Not working.

    When I open the attached file, it's blank.

  11. #11
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Using Mode to find the most popular values. Not working.

    The file in my prior post works ok for me I'm afraid - data is in Col Q onwards (only 1 sheet in file)

  12. #12
    Registered User
    Join Date
    03-04-2011
    Location
    Fremont, CA
    MS-Off Ver
    Excel 2008 for Mac
    Posts
    31

    Re: Using Mode to find the most popular values. Not working.

    This worked, and it seems like the best option right now

    Thank you very much.

  13. #13
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Using Mode to find the most popular values. Not working.

    Not sure if 2008 has Pivot Table Wizard or not. I normalized the data using the wizard and then created the pivot table. See attached. (this is a new trick I just learned )
    Attached Files Attached Files
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

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

+ 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