Counting distinct records

Posted on 2012-09-19
Last Modified: 2012-09-19
I have a (probably simple) question about access reporting.

I have a report that uses a query, resulting in some rows having the same value for one field (Job ID).
I have a text box in the report footer which has the Control source set to =Count([Job ID])

This works of course, but gives the total number of records, where I want the total of distinct records.

Is there any syntax that I can insert into that report text box to give me the Distinct value.  I tried Dcount([Job ID]) but it didn’t like that!!

Best regards

Question by:rltomalin

    Author Comment

    I also have the issue where I want to use a Sum function, but only applying to the distinct records.
    I assume the solution will be similar.


    LVL 39

    Assisted Solution

    There are many possible solutions. You can create separate query with JobIDs only (Group By), use this query as report source. You report in this case could be subreport.
    You can create separate subreport with count of distinct JobID.
    Here you can find how to construct select(Distinct):
    LVL 77

    Accepted Solution

    I'm afraid Distinct Count is something Access is not good at.

    If your report is based on a query 'qry1', then you can approach it like this...

    First build a second query (qry2) to get the distinct values...

    Select Distinct JobID from qry1

    Then in your report you can  create a textbox with the controlsource of...

    LVL 10

    Assisted Solution


    You need to do in to time. First you group the similar value jobid, and then you count it.

    There's the query :

    SELECT Count(Step1.Field1) AS CountTotalJobID
    FROM (SELECT Field1 FROM Table1 GROUP BY Field1) AS Step1;

    Open in new window

    Step1 doesn't matter, replace the Field1 by [Job ID] and the table1 by your table.


    Author Closing Comment

    Thanks to all three of you for your rapid feedback.  I have chosen to use the solution from Peter because it looked easiest to follow (for me) and simple.  It seems to be working OK.
    I gave some points to the others beacuse I am sure they are valid solutions.

    Hope that is OK.



    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    This isn't a frequent question on EE. I must have seen it three or four times (among several thousand questions). However, I use this trick quite often, most frequently as a delayed Current event. A form does not expose it's calculation dependenc…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now