Results 1 to 2 of 2
  1. #1
    adam6023 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2018
    Posts
    1

    Update Query Needed For Similar Excel Function Countif(B$1:B1,B1)

    I need a formula/query for column B in Access that would produce the result below. This would be in an update query where B would be the calculated field. In excel, the formula would be Countif(B$2:B2,B2) and would drag down so that the result would show the number of times that field has been seen above. I have millions of records so need a formula to produce this exact result.

    A B
    Ben 1
    Adam 1


    Chris 1
    Ben 2
    Ben 3
    Chris 2

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Requires a unique ID field, autonumber field should serve.

    One approach uses DCount domain aggregate function.

    SELECT ID, A, DCount("*", "TableName", "A='" & [A] & "' AND ID<" & [ID]) + 1 AS GrpSeq FROM tablename;

    However, with millions of records, I expect this will perform so slowly as to be non-functional. There is probably a way to do with a nested subquery but likely will also perform quite slowly.

    Textbox in report has RunningSum property which can easily calculate the sequence number in Group header/footer section.

    Now if you just want to know the total count and don't need to assign sequence number to each record, do an aggregate query.
    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. Countif function
    By Tazmaniac in forum Programming
    Replies: 8
    Last Post: 03-29-2018, 03:31 AM
  2. Replies: 2
    Last Post: 02-26-2017, 11:31 AM
  3. Replies: 7
    Last Post: 05-28-2015, 11:43 AM
  4. countif function no clue
    By juriemagic in forum Queries
    Replies: 7
    Last Post: 04-24-2015, 07:50 AM
  5. Similar to countif
    By JonHFL in forum Access
    Replies: 2
    Last Post: 06-04-2010, 10:55 AM

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