+ Reply to Thread
Results 1 to 14 of 14

Count unique values within a range that meet a specific condition

  1. #1
    Registered User
    Join Date
    05-18-2013
    Location
    Utrecht, The Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    7

    Count unique values within a range that meet a specific condition

    Hi to all,

    This is my first post to this forum which has already been a great help for several Excel issues I had to conquer.
    But now I am sweating on which formulas to use in order to count unique values within a range that meet a specific condition.

    Let's say my range is A1:C6.
    The cells in this range are either empty (blank) or contain a date in the format DD.MM.YYYY (defined by Format Cells - Number - Custom), for example 22.05.2013. Dates in this range are non-unique and are not sorted.

    Examplev (first 6 rows):
    A B C
    31.03.2013 13.04.2011
    15.02.2012 16.02.2012
    22.05.2013
    13.04.2011
    15.02.2012 16.02.2012
    29.01.2010

    When I needed to know the count of the unique values in the range A1:C6, I found on this forum the following formula, which works perfectly:
    =SUMPRODUCT((A1:C6<>"")/COUNTIF(A1:C6;A1:C6&""))

    The next step I need to take is to count the unique values in the range A1:C6 within the same year.
    To this purpose I entered in column D, rows 1 - 4: 2010, 2011, 2012 resp. 2013.

    My question is: which formula (please no VBA!) should I use in column E which returns the count of unique values in the year indicated on the same row in column D? So D1 should indicate the unique values in the year 2010, D2 in 2011, etc.

    Hope I explained myself well, your help is much appreciated, thanks in advance!
    CSS

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Count unique values within a range that meet a specific condition

    I would re-arange your data and after that use a pivot table.

    See the attached file.
    Attached Files Attached Files
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Registered User
    Join Date
    05-18-2013
    Location
    Utrecht, The Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Count unique values within a range that meet a specific condition

    Oeldere, thanks for your quick reply!
    Is it also possible to solve my issue by using formulas, so no VBA, no Pivot tables - else re-arranging my data will be my next head ache :-)
    BTW, of course the one but last sentence in my original post should have been:
    So E1 should indicate the unique values in the year 2010, E2 in 2011, etc.

  4. #4
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Count unique values within a range that meet a specific condition

    Maybe others can, but (at the moment) not by me.

  5. #5
    Valued Forum Contributor
    Join Date
    02-05-2013
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2013
    Posts
    571

    Re: Count unique values within a range that meet a specific condition

    Try this :
    Please Login or Register  to view this content.
    Note : use Ctrl+Shift+Enter
    Click (*) if you received helpful response.

    Regards,
    David

  6. #6
    Registered User
    Join Date
    05-18-2013
    Location
    Utrecht, The Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Count unique values within a range that meet a specific condition

    Thank you SDCh, I used your suggested formula in the xls-file that Oeldere enclosed in his first reply in this thread.
    I copied the formula with Ctrl+Shift+Enter there, but the result is: #VALUE!
    Could this be because the cells in range A1:C6 are not defined as numbers, but as dates by using Format Cells -> Number -> Custom > dd.mm.yyyy?
    Any suggestion to get the formula working with this date format?

  7. #7
    Valued Forum Contributor
    Join Date
    02-05-2013
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2013
    Posts
    571

    Re: Count unique values within a range that meet a specific condition

    Use Ctrl+F, on tab replace - find what type ".", and on replace with type "-" and press replace all.
    Don't forget format cell as date.

  8. #8
    Registered User
    Join Date
    05-18-2013
    Location
    Utrecht, The Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Count unique values within a range that meet a specific condition

    SDCH, thanks again for your solution, it works!

    Now I am not allowed to change date format as it is defined in my spreadsheet, it has to stay as it is (for definition: see previous my msg).
    So the FIND/REPLACE option is a "no go".
    Is there a way to automatically "convert" a date in my format to a date in another column with your format that will make the formula work?
    I tried several ways, such as concatenating, so a date 29.01.2010 is transformed to 29-1-2010 in the next column, where it is defined as a date according to your format, but the formula doesn't work :-(

  9. #9
    Valued Forum Contributor
    Join Date
    02-05-2013
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2013
    Posts
    571

    Re: Count unique values within a range that meet a specific condition

    Don't know what you mean, because on my Excel it's work.

    Note: Update excel from Oldere, see the format and the formula.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    05-18-2013
    Location
    Utrecht, The Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Count unique values within a range that meet a specific condition

    Sorry for not expressing myself clearly enough. That’s why I decided to put my situation in the file which is (hopefully) uploaded with this message.
    I used the columns H – S in the first sheet.

    Column H (green background) is the only column available for the user of my spreadsheet to enter the date.
    However, the date can also be two days, see entered examples.

    The other columns I – Q are hidden for the user and I use them to get the relevant dates separately in columns J – L (blue background).

    Orange background:
    column R shows the years for which the number of unique dates have to be counted
    column Q contains the =SUM(--(FREQUENCY(IF(YEAR($J$1:$L$6)=R1;$J$1:$L$6);($J$1:$L$6))>0)) formula entered with Ctrl+Shift+Enter which results in #VALUE!.

    Where do I go wrong?
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    05-18-2013
    Location
    Utrecht, The Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Count unique values within a range that meet a specific condition

    Please note the corrected column reference below.
    ------
    Sorry for not expressing myself clearly enough. That’s why I decided to put my situation in the file which is (hopefully) uploaded with this message.
    I used the columns H – S in the first sheet.

    Column H (green background) is the only column available for the user of my spreadsheet to enter the date.
    However, the date can also be two days, see entered examples.

    The other columns I – S are hidden for the user and I use them to get the relevant dates separately in columns J – L (blue background).

    Orange background:
    column R shows the years for which the number of unique dates have to be counted
    column S contains the =SUM(--(FREQUENCY(IF(YEAR($J$1:$L$6)=R1;$J$1:$L$6);($J$1:$L$6))>0)) formula entered with Ctrl+Shift+Enter which results in #VALUE!.

    Where do I go wrong?

  12. #12
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Count unique values within a range that meet a specific condition

    please don't use yellow as a highlight color,very hard to read (I think that says column S, but my poor eyes are not sure..)
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  13. #13
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Count unique values within a range that meet a specific condition

    hi CSS. you are getting VALUE errors because column H aren't dates recognised by Excel. They are texts. Excel recognise Dates as numbers. if you were to format cells for column A or B to General Format, you will see that it turns to numbers. Column H will not. hence, if you do a YEAR formula, Excel gives a VALUE error as it's a text. try this array formula instead:
    =SUM(FREQUENCY(IF(RIGHT($H$1:$H$6,4)=R1&"",MATCH($H$1:$H$6,$H$1:$H$6,0)),ROW($H$1:$H$6)-ROW($H$1)+1))

    Edit: overlooked the unique count. use:
    =SUM(IF(FREQUENCY(IF(RIGHT($H$1:$H$6,4)=R1&"",MATCH($H$1:$H$6,$H$1:$H$6,0)),ROW($H$1:$H$6)-ROW($H$1)+1)>0,1))
    Last edited by benishiryo; 06-21-2013 at 05:44 AM. Reason: amendment

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  14. #14
    Registered User
    Join Date
    05-18-2013
    Location
    Utrecht, The Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Count unique values within a range that meet a specific condition

    Hi benishiryo,

    Thanks for your reply and the provided formula.

    You apply your formula to my column H, which can also contain a range of two days as I already explained.
    Therefore your formula does not give correct results, see enclosed file in which I added your formula in column T.
    The count of unique dates in 2011 is 6, your formula gives 5.
    The count of unique dates in 2012 is 2, your formula gives 1.

    In order to get all dates separately, I used columns J, K and L.
    How do I get your formula working to get the unique dates for the years 2010 – 2015 whilst using columns J, K and L (instead of column H)?
    Thanks in advance for enlightening me!
    Attached Files Attached Files

+ 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