Solved

Dcount unique

Posted on 2016-11-14
6
22 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
6 Comments
 
LVL 49

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 26

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 49

Accepted Solution

by:
Ryan Chong earned 500 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 13

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 57
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Correct ordering 16 44
Why is my report opening in "MAX" view? 7 9
putting an icon in a form 13 20
add more styles to my code 2 16
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

758 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

20 Experts available now in Live!

Get 1:1 Help Now