• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

Counting distinct records

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
rltomalin
Asked:
rltomalin
3 Solutions
 
rltomalinAuthor Commented:
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
 
als315Commented:
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
 
peter57rCommented:
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
 
TobiasCommented:
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;

Open in new window


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

Regards
0
 
rltomalinAuthor Commented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now