Results 1 to 4 of 4
  1. #1
    Volodos86 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    3

    Count different rows in for same ID for the same year

    Hi guys
    I need your help, if possible.
    THe structure of the dataset is the following one:

    ID A Year
    1 J 1998
    1 R 2000


    1 J 1998
    1 J 1998
    2 Q 2001
    2 Q 1998

    The aim is to create a query that sum 1 when at least two (also the case with three is interesting for my purposes) objects in A per each ID are equal and in the same year. Is it possible?
    The output, given the example above, should be:

    ID EqualA_SameYear
    1 1
    2 0

    Thanks!!
    Volodos

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    In your example ID = 1, A = J, Year = 1998 (by the way you do not want to use reserved words for field names, YEAR is a reserved word and you will likely have problems with it if you continue to use it) you have 3 values, record 1, 3 and 4 so how do you arrive at a value of 1?

    Can you be more explicit about your calculation process because it's not apparent from what you've expressed.

  3. #3
    Volodos86 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    3
    Thank you for the reply!
    Yes there are three records, 1, 3, 4 where A is the same for the same ID and the same year. The output should be a dummy variable:
    1 whether there is at least a couple of records with the same A in the same year.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    SELECT ID, A, [Year], Count(ID) as DupCount FROM <TABLENAME> GROUP BY ID, A, [YEAR]

    this will give you a list of all your unqique ID, A and YEAR values and how many times they occur, then you can set a criteria in your DUPCOUNT field of > 1

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 09-10-2013, 05:32 PM
  2. Dsum data between to dates for this year and last year
    By sdel_nevo in forum Programming
    Replies: 1
    Last Post: 06-13-2013, 06:48 AM
  3. Replies: 4
    Last Post: 01-09-2013, 11:16 AM
  4. Replies: 4
    Last Post: 01-10-2012, 06:26 PM
  5. Replies: 1
    Last Post: 01-24-2011, 03:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums