[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Dcount unique

Posted on 2016-11-14
6
Medium Priority
?
72 Views
Last Modified: 2016-11-15
Experts, I have a count in a query but need to count only the unique ID's.  How could I modify the following statement:  
DCount("[ID]","qryOutstanding_2") AS [Count]

thank you

sql:
SELECT qryBal2_Works.FacilityType, qryBal2_Works.Utilized, tblType_dropbox.Type, DCount("[ID]","qryOutstanding_2") AS [Count]
FROM qryBal2_Works INNER JOIN tblType_dropbox ON qryBal2_Works.FacilityType = tblType_dropbox.ID
WHERE (((tblType_dropbox.Type) Like "Working*"));
0
Comment
Question by:pdvsa
[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
6 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41887477
quick try:

SELECT qryBal2_Works.FacilityType, qryBal2_Works.Utilized, tblType_dropbox.Type, 
(select count(*) from (select ID from qryOutstanding_2 group by ID)) as  AS [Count]
FROM qryBal2_Works INNER JOIN tblType_dropbox ON qryBal2_Works.FacilityType = tblType_dropbox.ID
WHERE (((tblType_dropbox.Type) Like "Working*"));

Open in new window

0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 41887479
Use Allen Browne's ECount. ECount() offers an extra argument so you can count distinct values. The other arguments are the same as DCount().
0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 41887480
typo for my comment, you can try this instead:
SELECT qryBal2_Works.FacilityType, qryBal2_Works.Utilized, tblType_dropbox.Type, 
(select count(*) from (select ID from qryOutstanding_2 group by ID)) AS [Count]
FROM qryBal2_Works INNER JOIN tblType_dropbox ON qryBal2_Works.FacilityType = tblType_dropbox.ID
WHERE (((tblType_dropbox.Type) Like "Working*"));

Open in new window

0
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!

 
LVL 18

Expert Comment

by:John Tsioumpris
ID: 41887484
The problem lies to qryOutstanding_2...you should have the query to return only unique values and then perform the Dcount....
0
 
LVL 58
ID: 41887533
And just as an aside, you should not be using Domain functions inside a query as you are guaranteeing yourself poor performance (the query optimizer cannot cost it).   Use another query and join to it, or sub-selects as Ryan showed.

 All the Domain functions are nothing more than a SQL statement with a wrapper, so there's no reason not to write it directly in SQL.

 They were only intended to be used in places where SQL was not allowed.

 This is one of the main reasons you hear about Access apps that die after 5 or 6 users.

Jim.
0
 

Author Closing Comment

by:pdvsa
ID: 41887659
Perfect.  thank you.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

650 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