?
Solved

Distinct Count in Access 2007

Posted on 2012-04-01
4
Medium Priority
?
888 Views
Last Modified: 2012-04-01
Hey guys,

Need to count distinct invoice numbers in the below query.  Have tried lots of ways to no effect... can someone please assist.

thanks

Rusty


SELECT [Working-rep+acc].[Sales Rep], Count ([Working-rep+acc].[Invoice Number]) AS  [CountOfInvoice Number]
FROM [Working-rep+acc]
GROUP BY [Working-rep+acc].[Sales Rep];
0
Comment
Question by:rustyroo
4 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 37792826
You just need to group by the Invoice Number as well.

SELECT [Working-rep+acc].[Sales Rep], [Working-rep+acc].[Invoice Number], Count ([Working-rep+acc].[Invoice Number]) AS  [CountOfInvoice Number]
FROM [Working-rep+acc]
GROUP BY [Working-rep+acc].[Sales Rep], [Working-rep+acc].[Invoice Number];
0
 
LVL 12

Expert Comment

by:FarWest
ID: 37792830
in access you should use sub-query for your select that contains the distinct select
something like

SELECT t.[Sales Rep], Count (t.[Invoice Number]) AS  [CountOfInvoice Number]
FROM (
SELECT distinct [Working-rep+acc].[Sales Rep], [Working-rep+acc].[Invoice Number]) AS t
GROUP BY [Working-rep+acc].[Sales Rep];
0
 
LVL 40

Accepted Solution

by:
als315 earned 2000 total points
ID: 37792835
If you have multiple entries for [Invoice Number] for each [Sales Rep], and you like to count only unique Invoice numbers, you should at first create query, where you will Group by Invoice Number and Sales Rep. In second query you will be able to count unique Invoice Numbers. Queries could be combined in one.
Result could be:

SELECT Count(Q1.[Invoice Number]) AS [CountOfInvoice Number], Q1.[Sales Rep]
FROM (SELECT [Working-rep+acc].[Invoice Number], [Working-rep+acc].[Sales Rep]
FROM [Working-rep+acc]
GROUP BY [Working-rep+acc].[Invoice Number], [Working-rep+acc].[Sales Rep]) As Q1
GROUP BY Q1.[Sales Rep];
0
 

Author Closing Comment

by:rustyroo
ID: 37793061
worked great thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

809 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