Results 1 to 6 of 6
  1. #1
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116

    Acheiving Countifs in a Query

    This is an offshot of my previous thread. I have a table that has many fields, four of which are relevant here: the unique ID, Issue, Engagement and Year. I want to create a query that shows me, for each row on that table, how many other rows have the same combination of Issue, Engagement and year. In other words, it's baiscally like a field with a countifs statement.

    I assume this would require one or more queries that makes use of the totals column. But I can't quite wrap my mind around how to pull it off. Can anyone give me a hint as to how I should structure the query or queries?

    Edit: One thing I tried was creating a query with a field that concatonated
    Issue, Engagement and Year and using "Count" from the total line. But I obviosuly don't know what I'm doing because that returned a result of 1 in each row.

  2. #2
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    433
    use Total query (the one with Sigma sign):

    Code:
    SELECT Issue, Engagement, [Year], Count("1") AS CountOfDups FROM YourTableName  
    GROUP BY Issue, Engagement, [Year];

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    This table has duplicates for Issue/Engagement/Year combination?
    If combination is unique then count will be 1 for each row.

    If there are duplicates, then build the aggregate query.
    Now if you want to show all fields from the table, join that query to table on the 3 pairs of fields.

    Alternative is a DCount() expression, however, domain aggregate functions can slow performance of query.

    Provide sample data and desired result as tables in post or attach file.

    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.

  4. #4
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116
    Quote Originally Posted by jojowhite View Post
    use Total query (the one with Sigma sign):

    Code:
    SELECT Issue, Engagement, [Year], Count("1") AS CountOfDups FROM YourTableName  
    GROUP BY Issue, Engagement, [Year];
    Wow, that looks like a step in the right direction. Thank you! I tried thgat and it gave me a table with four columns: Issue, Engagement, Year, and the countofdups. I suppose my question is how do I link that to the unique ID from my table? At the end of the day I basically want to create a query that shows the "countofdups" for each unique ID.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    See post 3.

    Alternatively, build a report and use Sorting & Grouping with aggregate calcs. This allows display of detail data and summary calcs without intermediate queries.
    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.

  6. #6
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116
    Quote Originally Posted by June7 View Post
    See post 3.

    Alternatively, build a report and use Sorting & Grouping with aggregate calcs. This allows display of detail data and summary calcs without intermediate queries.
    Thank you! This solution worked for me.

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

Similar Threads

  1. Countifs with unique values in access report
    By FJMSalgueiro in forum Access
    Replies: 13
    Last Post: 01-18-2024, 08:25 PM
  2. Replies: 3
    Last Post: 01-29-2013, 08:59 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