Solved

Distinct Count in Access 2007

Posted on 2012-04-01
4
846 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 39

Accepted Solution

by:
als315 earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

895 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

11 Experts available now in Live!

Get 1:1 Help Now