+ Reply to Thread
Results 1 to 9 of 9

Count Unique items per Categ

  1. #1
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Count Unique items per Categ

    Hi all... not sure if this is best handled via formula or vba code, but am pulling my hair out trying to collect some metrics for a weekly report. I would assume that because of the potential volume, vba would be a bit faster, but I'm not concerned with speed at this point.

    I'm attaching a sample worksheet in case the boatloads of sinus medication I've had today renders me unable to clearly explain what I'm trying to do.

    You will see that there are two columns in my sample set. ID (which can vary from one to hundreds of thousands) and Category (which will always be the same 6 values), neither of which are unique. I need to be able to provide a count of unique ID's per category - almost the opposite of what a countifs would give.

    So even though ID NU0P2KBE07I9 is listed many times, 3 of which are for category "Topics-Important" I can only count it ONCE for "Topics-Important"

    Hope that makes sense....

    Thank you for any help!

    EDIT: I apologize - there was a database error so I was unable to access the post again, then lost my internet connection at home for most of the weekend. I have attached the file.
    Attached Files Attached Files
    Last edited by JP Romano; 01-11-2016 at 09:11 AM.

  2. #2
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Count Unique items per Categ

    Unfortunately I see no attachment to your post
    Spread the love, add to the Rep

    "None of us are as smart as all of us."

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

    Re: Count Unique items per Categ

    Try something like this...

    Data Range
    A
    B
    C
    D
    E
    1
    ID
    Cat
    Cat
    Unique IDs
    2
    4
    Cat1
    Cat1
    2
    3
    7
    Cat1
    Cat2
    1
    4
    7
    Cat2
    Cat3
    2
    5
    3
    Cat3
    Cat4
    3
    6
    5
    Cat3
    Cat5
    2
    7
    5
    Cat3
    8
    4
    Cat4
    9
    7
    Cat4
    10
    10
    Cat4
    11
    10
    Cat4
    12
    3
    Cat5
    13
    3
    Cat5
    14
    3
    Cat5
    15
    9
    Cat5
    16
    ------
    ------
    ------
    ------
    ------


    This array formula** entered in E2 and copied down:

    =SUM(IF(FREQUENCY(IF(B$2:B$15=D2,MATCH(A$2:A$15,A$2:A$15,0)),ROW(A$2:A$15)-ROW(A$2)+1),1))

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

  4. #4
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Count Unique items per Categ

    Tony - thank you very much... that seems to do the trick!

    Is there a way to use the end of the range as a variable and execute the CTRL+ALT+SHIFT automatically? It's not a big deal to do it manually, of course, but if I send this file over to some end users they may not remember to make the changes.

    Thank you again for this... I rarely use formulas (especially arrays) because I find the syntax to be most confusing and hard to unwind when there are problems - but this one seems manageable for somebody with my moderate level of understanding.

    Appreciate it!

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

    Re: Count Unique items per Categ


  6. #6
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Count Unique items per Categ

    g2
    Please Login or Register  to view this content.
    try the above and copy towards down
    but it will take much time to evaluate formula (to give result)
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  7. #7
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Count Unique items per Categ

    Siva - that's tremendous... thank you. Can you tell me what the "zzzzzz" is for? It seems to work with that in there, though it feels like I should be replacing it with something!

    Tony - thank you for the named range reminder.... I completely forgot about them.

    You guys are amazing - thank you so much.

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

    Re: Count Unique items per Categ

    Quote Originally Posted by nflsales View Post
    but it will take much time to evaluate formula (to give result)
    That formula is very inefficient.

  9. #9
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Count Unique items per Categ

    Quote Originally Posted by Tony Valko View Post
    That formula is very inefficient.
    May I know where is the wrong in the formula

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Count Unique Items in a Column Based on Unique Items in Two Other Columns
    By HangMan in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 10-31-2015, 04:48 PM
  2. [SOLVED] count of unique listview items
    By Kiran2012 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 01-08-2013, 07:43 AM
  3. Count Unique Items
    By e602043 in forum Excel General
    Replies: 4
    Last Post: 10-05-2011, 07:43 PM
  4. Count unique items within a choice
    By mkvassh in forum Excel General
    Replies: 3
    Last Post: 03-02-2011, 05:45 AM
  5. Count Unique Items in PivotTable?
    By EnergyEngineer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-29-2008, 12:00 PM
  6. Count Unique Items
    By Karleajensar in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-05-2008, 05:20 PM
  7. Count unique items in column.
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-19-2008, 10:14 AM

Tags for this Thread

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