Solved

Distinct Count in Access 2007

Posted on 2012-04-01
4
875 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

737 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