Solved

# Counting distinct records

Posted on 2012-09-19
345 Views
Hello
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

Richard
0
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.

Regards

Richard
0

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):
http://blogs.office.com/b/microsoft-access/archive/2007/09/19/writing-a-count-distinct-query-in-access.aspx
0

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...

=Dcount("*","qry2")
0

LVL 10

Assisted Solution

Dear,

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;
``````

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

Regards
0

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.

Regards

Richard
0

## Featured Post

### Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), 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…