+ Reply to Thread
Results 1 to 5 of 5

Count Unique Values IF a Column Contains Data

  1. #1
    Registered User
    Join Date
    02-10-2017
    Location
    San Diego
    MS-Off Ver
    2007
    Posts
    2

    Count Unique Values IF a Column Contains Data

    So I've been looking through many posts on this forum as well as other sites like exceljet and mrexcel, but I could not find an answer to my below issue. If I've overlooked a thread that you think would be helpful, then please let me know!

    I have a set of columns with data in the rows below the columns. I am attempting to count the unique values in column A by the three various care levels that are in column D. I've tried a few different formulas including countif, sumif, sumproduct with a 1/countif, frequency, etc but I just can't put one together to get me the info.

    I am using Office 2007 and in the below data, I would basically want to know how many units are AL, IL, and DM. It should be 2 AL, 3 IL, 3 DM. So I would want a formula that does IF column D contains AL count how many unique values are in column A.

    Please Login or Register  to view this content.
    Any help is greatly appreciated, and if there's additional info that I didn't provide please let me know! Thanks!
    Last edited by JBeaucaire; 02-11-2017 at 12:26 AM.

  2. #2
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Count Unique Values IF a Column Contains Data

    Welcome SDowney,

    Assuming you have AL etc in F1:F3, and the data is in A1:D12, then in call G2

    =SUMPRODUCT(1/COUNTIF($A$2:$A$12,$A$2:$A$12),--($D$2:$D$12=F1)) and copy down.

    This gives the result you are looking for.

    I hope this helps, please let me know!

    Regards,

    David

    If this has been helpful
    - Please click on the *Add Reputation button at the bottom left.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".


  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Count Unique Values IF a Column Contains Data

    The formula shown in H2 is
    =SUM(INDEX(($D$1:$D$12=F2)*(MATCH($A$1:$A$12,$A$1:$A$12,0)=ROW($A$1:$A$12)),0))

    Data Range
    A
    B
    C
    D
    E
    F
    G
    H
    1
    Unit
    Type
    Privacy
    Care Level
    2
    1
    alstudio
    PRI
    AL
    AL
    2
    =SUM(INDEX(($D$1:$D$12=F2)*(MATCH($A$1:$A$12,$A$1:$A$12,0)=ROW($A$1:$A$12)),0))
    3
    2
    al2br
    SPA
    AL
    DM
    3
    4
    2
    al2br
    SPB
    AL
    IL
    3
    5
    3
    al1br
    PRI
    DM
    6
    4
    al1br
    SPA
    DM
    7
    4
    al1br
    SPB
    DM
    8
    5
    al2br
    SPA
    IL
    9
    5
    al2br
    SPB
    IL
    10
    6
    alstudio
    PRI
    DM
    11
    7
    al2br
    PRI
    IL
    12
    9
    al1br
    PRI
    IL
    Last edited by JBeaucaire; 02-11-2017 at 12:34 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    02-10-2017
    Location
    San Diego
    MS-Off Ver
    2007
    Posts
    2

    Re: Count Unique Values IF a Column Contains Data

    Thank you for your help, David. The formula works great! But I do have one issue, that if the there is a blank in column A the formula gets an error. Is there a way around that?

  5. #5
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    18,879

    Re: Count Unique Values IF a Column Contains Data

    With some modification/transformation Jerry's formula will work when there is a blank in column A.
    Using the setup in post #3, select cell G2 and paste the following array entered formula* into the formula bar:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    *After pasting the formula into the formula bar, activate the formula by simultaneously pressing Ctrl, Shift and Enter. You will then be able to copy the formula down.
    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

+ 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 number of unique values in Column A that match a term in Column B
    By frsaxon in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-29-2016, 07:22 AM
  2. Replies: 4
    Last Post: 10-09-2015, 05:19 AM
  3. Replies: 2
    Last Post: 08-19-2015, 10:22 AM
  4. Count Unique values in Column based on values in other columns
    By dmschave in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-17-2014, 11:06 AM
  5. Replies: 8
    Last Post: 05-15-2013, 04:50 PM
  6. [SOLVED] Macro to count unique values in a column, enter it in next column, then delete duplicates
    By pmorisse in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2013, 03:27 PM
  7. Count Unique Values In One Column Basis Unique Values in Another Column
    By shez_raz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-07-2012, 01:55 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