Results 1 to 6 of 6
  1. #1
    spherehunter is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    3

    Access Unique Count


    I'm trying to add a value of 1 in a new column for every unique value in lm_filler 2 and 0 for the duplicates. Can this be done?

    Click image for larger version. 

Name:	Capture.PNG 
Views:	13 
Size:	53.2 KB 
ID:	7660

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You want a 1 for the first occurence of Im_filler2 and a 0 for each repeat? What determines the first - seqno? Not sure an UPDATE query can do this. Might require VBA.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    spherehunter is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    3
    Quote Originally Posted by June7 View Post
    You want a 1 for the first occurence of Im_filler2 and a 0 for each repeat? What determines the first - seqno? Not sure an UPDATE query can do this. Might require VBA.
    Correct in a new field. Seqno can be used to determine the first occurrence.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Here is what I find:

    I can build a query that will assign a count value to each record in each Im_filler2 group:
    SELECT seqno, Im_filler2, (SELECT Count(Im_filler2) +1 As CountIM FROM Table1 As Dupe WHERE Dupe.seqno<Table1.seqno AND Dupe.Im_filler2 = Table1.Im_filler2) AS Category
    FROM Table1;

    Then I attempt to use this query to update a new field in table (I manually added to table a field called Cat):
    UPDATE Query1 INNER JOIN Table1 ON Query1.seqno = Table1.seqno SET Table1.Cat = IIf([Query1].[Category]>1,0,1);

    That generates error, as I expected it would, 'Operation must use an updateable query.'

    What you can do is make a table from the first query then use it in place of the query in the UPDATE.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    spherehunter is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    3
    I got it to work with this:

    Unique: IIf(DCount("*","MTD Call","[lm_filler2]=" & Chr(34) &
    [lm_filler2] & Chr(34) & " AND [Seqno]<" & [Seqno])=0,1,0)

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Wonderful! If it's not too slow. Domain aggregate functions can be very slow with large datasets. I never looked at DCount for this, always went with the subquery. A new trick in my bag. Thank you.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Unique queries - Unique Count
    By bigfish in forum Queries
    Replies: 7
    Last Post: 03-14-2012, 01:28 PM
  2. Count unique records - no duplicates
    By Kevo in forum Queries
    Replies: 4
    Last Post: 08-15-2011, 01:19 AM
  3. Count Unique Records
    By PonderingAccess in forum Queries
    Replies: 2
    Last Post: 08-19-2010, 06:54 AM
  4. Replies: 1
    Last Post: 08-18-2010, 02:36 AM
  5. Count of Unique Values
    By vsmk in forum Queries
    Replies: 2
    Last Post: 03-14-2010, 12:07 AM

Tags for this Thread

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