?
Solved

Distinct Count in Access 2007

Posted on 2012-04-01
4
Medium Priority
?
881 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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