+ Reply to Thread
Results 1 to 5 of 5

count unique values based on 1 condition

  1. #1
    Registered User
    Join Date
    09-21-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    39

    count unique values based on 1 condition

    Please can you show me how to count unique values based on 1 condition.
    Column A contains client names. Column B contains the subject. I want to count the number of unique clients per subject.

    Thanks

  2. #2
    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 values based on 1 condition

    Try this...

    Data Range
    A
    B
    C
    D
    E
    1
    Client
    Subject
    ------
    Subject
    Count
    2
    A
    XXX
    PPP
    2
    3
    A
    XXX
    XXX
    3
    4
    A
    ZZZ
    ZZZ
    1
    5
    B
    PPP
    RRR
    1
    6
    C
    PPP
    7
    C
    XXX
    8
    D
    RRR
    9
    D
    XXX
    10
    D
    RRR


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

    =SUM(IF(FREQUENCY(IF(B$2:B$10=D2,MATCH(A$2:A$10,A$2:A$10,0)),ROW(B$2:B$10)-ROW(B$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.

  3. #3
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: count unique values based on 1 condition

    Or this

    in D2

    =SUMPRODUCT((B1:B6=D1)/COUNTIFS(A1:A6,A1:A6,B1:B6,B1:B6&""))


    For Excel 2003 use this array formula

    =SUM(IF(FREQUENCY(IF((B$1:B$6=D1),MATCH(A$1:A$6,A$1:A$6,0)),MATCH(B$1:B$6,B$1:B$6,0))>0,1))

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.

    Row\Col
    A
    B
    C
    D
    1
    Steve Subject1 Subject1
    2
    John Subject2
    2
    3
    Steve Subject1
    4
    Andrew Subject3
    5
    Steve Subject2
    6
    John Subject1
    Last edited by AlKey; 12-05-2014 at 09:37 PM.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  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: count unique values based on 1 condition

    According to their profile, they're using Excel 2003.

    COUNTIFS is not available in that version.

  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 values based on 1 condition

    The SUM/IF/FREQUENCY array formula is significantly faster to calculate compared to the SUMPRODUCT/COUNTIFS formula.

    On large ranges the difference is huge.

    Also, in the array formula using MATCH/ROW is faster to calculate compared to MATCH/MATCH.

+ 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 text, excluding space, based on one condition
    By asfa in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-01-2013, 02:33 PM
  2. Count Unique Discrete Values for specified date and given condition
    By JAUrrutia9 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-03-2013, 03:15 PM
  3. Count unique values based on condition
    By pradeev in forum Excel General
    Replies: 4
    Last Post: 06-12-2012, 10:43 AM
  4. Replies: 2
    Last Post: 01-17-2012, 07:48 AM

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