Access Issues DCount

cmcreynolds

Active Member
Joined
May 21, 2015
Messages
295
Hello again everyone -

Again, I'm used to PowerQuery/PowerPivot and I am needing some of that functionality.

This is only a part of a larger (but not that large) report that I'm building in Access 2013.

I'm trying to summarize and UNIQUELY count member IDs but as it splits across months (I would do this in PowerPivot using CountAX or if I summed, SUMX). I know Access and PowerPivot are two different software, but I was hoping to find something similar.

First, does DCount in Access not "uniquely" count? If I'm using it wrong, then my second question won't make sense-

Second, I have a simple table with the month number and month names because my report would have all 12 months listed, even if it was only run in January (not my choice).

Here is the SQL from this query:

Code:
SELECT [BOGExam-Registered].Year, MonthLookup.MonthNumber, MonthLookup.MonthName, DCount("ID","BOGExam-Registered","Indicator='NewCred'") AS ExamRegistCountNew, DCount("ID","BOGExam-Registered","Indicator='OldCred'") AS ExamRegistCountOld, DCount("ID","BOGExam-Registered","Indicator='Recert'") AS ExamRegistCountRecert
FROM [BOGExam-Registered] RIGHT JOIN MonthLookup ON [BOGExam-Registered].Month = MonthLookup.MonthNumber
GROUP BY [BOGExam-Registered].Year, MonthLookup.MonthNumber, MonthLookup.MonthName
ORDER BY MonthLookup.MonthNumber;

But, when I run the query, it repeats the totals for every month:

YearMonthNumberMonthNameExamRegistCountNewExamRegistCountOldExamRegistCountRecert
20171January0531

2February0531

3March0531

4April0531

5May0531

6June0531

7July0531

8August0531

9September0531

10October0531

11November0531
201712December0531

<tbody>
</tbody>

The table should look like this:

YearMonthNumberMonthNameExamRegistCountNewExamRegistCountOldExamRegistCountRecert
20171January0530

2February000

3March000

4April000

5May000

6June000

7July000

8August000

9September000

10October000

11November000
201712December001

<tbody>
</tbody>


Can anyone help me figure out how to correctly utilize DCount (if that is, in fact, what I should use)?

Thank you in advance.
 
Do you think my issue is that "BOGExam-Registered" is a query instead of a table?

The [Indicator] field is based on if statements of joined tables:
IIf([Pre2017Applicants]![FULL_NAME]<>"","OldCred",IIf([FellowRecertCheck]![ID]<>"","Recert","NewCred")) AS [INDICATOR]
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Do you think my issue is that "BOGExam-Registered" is a query instead of a table?
I don't think that should make a difference.
 
Upvote 0
In that query I have it filtered for everything after #1/1/2017#, so nothing should show up in any other month (besides the error for the 12/31/2017)
 
Upvote 0
Also, I need distinct counts of IDs in case a record is duplicated. That won't be caught in the Sum(IIf... statements, right?
 
Upvote 0
If you want my help, please do what I asked and provide sample data sets and expected results. It does not do any good if I set up something on my side that works for me but not for you, because I made assumptions that do not accurately reflect what you are really working with. Be sure to include in your examples data situations which are causing your issues.

Whether the data is coming from a table or query is inconsequential.
 
Last edited:
Upvote 0
Sorry, I'm not trying to be difficult, but the data I provided yesterday is exactly what I'm working with. I just took resulting data and used the top few row for post #3. Also, in my initial post, I listed what I felt it should look like and that I needed exactly distinct counts.

Which assumptions did I confuse? I do need help, but I thought that I expressed in the first post what I needed. What can I do to clarify it?
 
Upvote 0
Based on the data you supplied, my solution returns what you want, right?
So then the sample data you provided does not cause the problem/situation you are describing.
You need to provide a sample set that, contained unto itself, returns the unexpected results.
For all we know, it might be those other rows in your data set that you did not include in the example that are causing the issues.
We need to create a scenario where you and I are working with the EXACT same set of data.

Create a table or query that shows only EXACTLY those record you posted as your example for me. Then use that table/query in the query code I provided.
What do those results look like? Do they look like what I showed as my results?

If they do, and the issue is not found there, you need to give me a sample set that DOES cause the issues you are talking about to appear.
If they do not match, they we need to look at why - making sure that we are both using the exact same data.
 
Upvote 0
A possible SQL Solution:
Code:
SELECT 
	t1.[Month], 
	t1.[Year], 
	t1.INDICATOR, 
	Count(t1.INDICATOR) AS Total
FROM 
	Table1 t1
GROUP BY 
	t1.[Month], 
	t1.[Year], 
	t1.INDICATOR;

Based on your posted data in Post #3 results are:
------------------------------------
| Month | Year | INDICATOR | Total |
------------------------------------
|     1 | 2017 | OldCred   |     4 |
|     1 | 2017 | Recert    |     1 |
|    12 | 2017 | OldCred   |     1 |
------------------------------------


For what it's worth I thought the posted data incomplete because only one record for one of the categories in month 1, and only only record for month 12 (and no expected results) - so hard to test adequately.
 
Last edited:
Upvote 0
Here is the complete results table from the "BOGExam-Registered" query. I had to remove the names and emails because of security (is that okay?)

So, there are no "NewCert" records and no months besides January (1) and the one for December (12) -
IDMEMBER_TYPEACTIVITY_TYPEPRODUCT_CODEDESCRIPTIONStartDateINDICATORMonthYear
385087MEMBBOGEXAMACHE
1/4/2017OldCred12017
396501MEMBBOGEXAMBOGHM
1/24/2017OldCred12017
639219FELLBOGEXAMBOGHM
1/24/2017Recert12017
654907MEMBBOGEXAMBOGHM
12/31/2017OldCred122017
658262MEMBBOGEXAMBOGHM
1/13/2017OldCred12017
713959MEMBBOGEXAMBOGHM
1/2/2017OldCred12017
743740MEMBBOGEXAMBOGHM
1/12/2017OldCred12017
767818MEMBBOGEXAMBOGHM
1/19/2017OldCred12017
775230MEMBBOGEXAMBOGHM
1/24/2017OldCred12017
781184MEMBBOGEXAMACHE
1/23/2017OldCred12017
782113MEMBBOGEXAMACHE
1/23/2017OldCred12017
788210MEMBBOGEXAMBOGHM
1/14/2017OldCred12017
789030MEMBBOGEXAMBOGHM
1/16/2017OldCred12017
790182MEMBBOGEXAMBOGHM
1/13/2017OldCred12017
792932MEMBBOGEXAMACHE
1/24/2017OldCred12017
806347MEMBBOGEXAMBOGHM
1/23/2017OldCred12017
807213MEMBBOGEXAMBOGHM
1/3/2017OldCred12017
816339MEMBBOGEXAMBOGHM
1/19/2017OldCred12017
824480MEMBBOGEXAMACHE
1/4/2017OldCred12017
828742MEMBBOGEXAMBOGHM
1/10/2017OldCred12017
838975MEMBBOGEXAMBOGHM
1/3/2017OldCred12017
846124MEMBBOGEXAMBOGHM
1/16/2017OldCred12017
848492MEMBBOGEXAMBOGHM
1/9/2017OldCred12017
850107MEMBBOGEXAMACHE
1/23/2017OldCred12017
850201MEMBBOGEXAMBOGHM
1/17/2017OldCred12017
853282MEMBBOGEXAMBOGHM
1/17/2017OldCred12017
859861MEMBBOGEXAMBOGHM
1/19/2017OldCred12017
859921MEMBBOGEXAMACHE
1/10/2017OldCred12017
860424MEMBBOGEXAMBOGHM
1/16/2017OldCred12017
868025MEMBBOGEXAMBOGHM
1/12/2017OldCred12017
871421MEMBBOGEXAMBOGHM
1/5/2017OldCred12017
877627MEMBBOGEXAMBOGHM
1/6/2017OldCred12017
877759MEMBBOGEXAMBOGHM
1/3/2017OldCred12017
879603MEMBBOGEXAMBOGHM
1/5/2017OldCred12017
882965MEMBBOGEXAMACHE
1/25/2017OldCred12017
887416MEMBBOGEXAMBOGHM
1/25/2017OldCred12017
892565MEMBBOGEXAMBOGHM
1/20/2017OldCred12017
897041MEMBBOGEXAMBOGHM
1/20/2017OldCred12017
900137MEMBBOGEXAMBOGHM
1/12/2017OldCred12017
902764MEMBBOGEXAMACHE
1/16/2017OldCred12017
902797MEMBBOGEXAMBOGHM
1/6/2017OldCred12017
906022MEMBBOGEXAMBOGHM
1/16/2017OldCred12017
907790MEMBBOGEXAMBOGHM
1/10/2017OldCred12017
909225MEMBBOGEXAMBOGHM
1/3/2017OldCred12017
909878MEMBBOGEXAMBOGHM
1/11/2017OldCred12017
912508MEMBBOGEXAMBOGHM
1/3/2017OldCred12017
915778MEMBBOGEXAMBOGHM
1/12/2017OldCred12017
916508MEMBBOGEXAMBOGHM
1/4/2017OldCred12017
922023MEMBBOGEXAMBOGHM
1/20/2017OldCred12017
926520MEMBBOGEXAMBOGHM
1/18/2017OldCred12017
927229MEMBBOGEXAMACHE
1/11/2017OldCred12017
928815MEMBBOGEXAMBOGHM
1/4/2017OldCred12017
933730MEMBBOGEXAMBOGHM
1/24/2017OldCred12017
934450MEMBBOGEXAMACHE
1/24/2017OldCred12017
942501MEMBBOGEXAMBOGHM
1/24/2017OldCred12017
942921MEMBBOGEXAMBOGHM
1/18/2017OldCred12017
943491MEMBBOGEXAMACHE
1/25/2017OldCred12017
964721MEMBBOGEXAMACHE
1/23/2017OldCred12017

<caption> BOGExam-Registered </caption> <thead>
</thead> <tbody>
</tbody> <tfoot></tfoot>


Here is the Month Lookup Table:

MonthNumberMonthNameYear
1January2017
2February2017
3March2017
4April2017
5May2017
6June2017
7July2017
8August2017
9September2017
10October2017
11November2017
12December2017

<caption> MonthLookup </caption> <thead>
</thead> <tbody>
</tbody> <tfoot></tfoot>

When I run this query:

Code:
SELECT MonthLookup.Year, MonthLookup.MonthNumber, MonthLookup.MonthName, Sum(IIf([Indicator]="NewCred",1,0)) AS ExamRegistCountNew, Sum(IIf([Indicator]="OldCred",1,0)) AS ExamRegistCountOld, Sum(IIf([Indicator]="Recert",1,0)) AS ExamRegistCountRecert
FROM MonthLookup LEFT JOIN [BOGExam-Registered] ON (MonthLookup.Year = [BOGExam-Registered].Year) AND (MonthLookup.MonthNumber = [BOGExam-Registered].Month)
GROUP BY MonthLookup.Year, MonthLookup.MonthNumber, MonthLookup.MonthName
ORDER BY MonthLookup.Year, MonthLookup.MonthNumber;

I receive this results table:
YearMonthNumberMonthNameExamRegistCountNewExamRegistCountOldExamRegistCountRecert
20171January0561
20172February100
20173March100
20174April100
20175May100
20176June100
20177July100
20178August100
20179September100
201710October100
201711November100
201712December010

<caption> Query1 </caption> <thead>
</thead> <tbody>
</tbody> <tfoot></tfoot>


What I still need, though, after the 1s for ExamRegistCountNew are resolved, is a check to make sure it would count IDs uniquely. That's why I tried DCount, first.
 
Upvote 0
1) are there "NewCert" records in the data? If so, I'd leave a few records in - that's relevant as information you do *not* want to count in the results.
2) curious are the start dates reliable for month and year? If so, you don't need the month and year columns (or the month lookup table).
 
Upvote 0

Forum statistics

Threads
1,221,771
Messages
6,161,847
Members
451,723
Latest member
Rachetsely

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top