+ Reply to Thread
Results 1 to 9 of 9

calculating unique entries based on specific condition

  1. #1
    Registered User
    Join Date
    04-25-2007
    Posts
    4

    calculating unique entries based on specific condition

    Hi, I have been struggling with this problem for days, and I can't find a solution. I would really appreciate it, if someone could give a suggestion.

    By using the auto-filter option in Excel, I have the answer straight away, but automatically calculating this is a pain (or at least for me).

    I have attached a spreadsheet with example data to illustrate.

    The problem
    Column A has a text string (3 variations to choose from)
    Column B has a text string (7 different options)
    [B]-> [/B]For all values in column A matching the criteria, I need to count the unique instances in the relative column B

    I can calculate the number of different instances in a row, based with the following formula: {=SUM(IF(LEN(B1:B24),1/COUNTIF(B1:B24,B1:B24)))} The If(LEN) part is to ensure empty cells are not causing an error.

    Now I need to built in the factor to only count the unique instances for those cells for which cell A matches the criteria.

    I would really appreciate some suggestions.

    Best,
    Wouter.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525
    Hi there,

    As you've said that you can achieve your desired result by using the AutoFilter, you can then use one of the 11 available SUBTOTAL functions to perform whatever function you want on your filtered (visible) rows.

    Have a look at the attached where cells B33, B34 and B35 count the number of filtered instances of One, Two and Three respectively.

    HTH

    Robert
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    04-25-2007
    Posts
    4
    Hi, thanks for this.

    Unfortunately it doesn't give me the desired outcome. In my original spreadsheet, those numbers are the bottom are the results that it should produce (4, 3 and 5 respectively).

    In your model, there is also the assumption that row A is already sorted, which is not necessarily the case.

    I actually made one mistake in my original post. I meant to say that I get the desired results by using the advanced filter, and sorting on unique records.

    Best,
    Wouter.

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525
    Hi there,

    I inserted a blank row to allow for headings for filtering purposes - it doesn't matter if the data is sorted or not.

    Assuming it's OK to have an additional column (which could be hidden if you wish), have a look at this attachement which makes use of your original formula.

    HTH

    Robert
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    04-25-2007
    Posts
    4
    Thanks again.
    I'm afraid this isn't the solution either. in this case you still assume that the columns are sorted, as your formula is only covering the columns One, Two or Three respectively.

    The formula I'm looking for looks at all 24 columns, and based on the value in column A, it should keep the value of column B in the set. than only counting the unique instances for column B.

    1. look in A1:A24 and match criteria (say "one")
    2. for those matches in 1., use the value of column B in a set
    3. count the unique instances of the set created at 2. (for this, 1/countif(range,range) proofs to work)

    Wouter.
    Last edited by wjharing; 04-27-2007 at 09:03 AM.

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525
    Hi there,

    I've provided two possible solutions.

    1 - The macro (Macro1) on Problem v2 Excel when executed (Alt+F8) populates cells B32, B33 and B34 with the unique records for One, Two and Three respectively (based on the 21 possible combinations you have mentioned). This is the case regardless of what order the data is in (though may take a little while for large datasets).

    2 - The rptUniqueRecords report on the Problem v2 Access database will produce the required figures. This report is based on the data in the tblRawData table.

    Beyond these solutions, I cannot think of any other alternative.

    HTH

    Robert
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    04-25-2007
    Posts
    4
    Thanks for your help again.

    Access: unfortunately I have to restrict this problem to Excel due to the usage of the spreadsheet.

    Excel: the macro only works correctly when using any of the 8 options in the data sheet. it is however not generic. In my situation I can expect any kind of data in the B column. Only column A is limited to a pre-set of say 10 options.

    in the long run, I have done it as follows:
    have hidden columns C, D, E, etc. in column C1:C24 use =if(A1=One,$B1). in Columns D1:D24 use =if(A1=Two,$B1), etc.
    Than at bottom of each hidden column, use the function =sum(1/countif(range,range)

    This works correctly, so in the long run I have had to give up finding a single formula doing the same thing.

    Wouter.

  8. #8
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    Hi,

    Have a look at the below links:
    (I haven't been here for a while & I'm not sure if I need the html tags so I've included them to be on the safe side).

    HTML Code: 
    HTML Code: 
    HTML Code: 
    I should have a working example in my archive folders at work & will see if I can find it for you tomorrow but hopefully one of the above will help. There is a lot more related info on Chip's page (the last link) which may also come in handy.

    Good luck,
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  9. #9
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525
    One last suggestion would be to try the template at http://www.myzips.com/download/Excel-List-Compare.phtml

+ 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