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.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I think you may want to use the Aggregate Function COUNT instead of DCOUNT.
Your query looks a little odd because typically you see either the use of an Aggregate Query OR functions like DCOUNT, but not both blended in the same query.

How you query needs to be written, I cannot say for sure because I don't know what the data in your data tables used in your query looks like.
 
Upvote 0
Would it help to post a few rows of the other table?

IDLAST_FIRSTEMAILMEMBER_TYPEACTIVITY_TYPEPRODUCT_CODEDESCRIPTIONStartDateINDICATORMonthYear
385087Sith, Manny
email@email.com
MEMBBOGEXAMACHE
1/4/2017OldCred12017
396501Leia, Princess
email@email.com
MEMBBOGEXAMBOGHM
1/24/2017OldCred12017
639219
Hammill, Mark
email@email.com
FELLBOGEXAMBOGHM
1/24/2017Recert12017
654907Rickton, Mary
email@email.com
MEMBBOGEXAMBOGHM
12/31/2017OldCred122017
658262Keffler, Nick
email@email.com
MEMBBOGEXAMBOGHM
1/13/2017OldCred12017
713959
Stark, Tony
email@email.com
MEMBBOGEXAMBOGHM
1/2/2017OldCred12017

<caption> BOGExam-Registered </caption> <thead>
</thead> <tbody>
</tbody> <tfoot></tfoot>
 
Last edited:
Upvote 0
Try this:
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.MonthNumber = [BOGExam-Registered].Month) AND (MonthLookup.Year = [BOGExam-Registered].Year)
GROUP BY MonthLookup.Year, MonthLookup.MonthNumber, MonthLookup.MonthName
ORDER BY MonthLookup.Year, MonthLookup.MonthNumber;
 
Last edited:
Upvote 0
This resulted in 1s in the months with no data (Feb-Nov)
YearMonthNumberMonthNameExamRegistCountNewExamRegistCountOldExamRegistCountRecert
20171January0561
20172February100
20173March100
20174April100
20175May100
20176June100
20177July100
20178August100
20179September100
201710October100
201711November100
201712December010

<caption> Query1 </caption> <thead>
</thead> <tbody>
</tbody> <tfoot></tfoot>
 
Upvote 0
That is not what I got. This is what it showed for me, based on your example, which looks correct.
YearMonthNumberMonthNameExamRegistCountNewExamRegistCountOldExamRegistCountRecert
20171January041
20172February000
20173March000
20174April000
20175May000
20176June000
20177July000
20178August000
20179September000
201710October000
201711November000
201712December010

<tbody>
</tbody>

If you copied my code, verbatim, and are not getting expected results, I suspect maybe a data issue.
 
Last edited:
Upvote 0
Yeah, I copied it verbatim and still get 1s as above. And luckily the BOGExam-Registered is only 58 records and I can scan and there are no "NewCred" in any records (in the INDICATOR field). All the records are in January 2017 (with the one exception for December 2017, which is a data input error, but I felt it helped me know how things were progressing in my table).

I'm using Access 2013, is that what you're using? I am wondering if there's something in my settings that is causing the 1s in the months with no data?
 
Upvote 0
I am using Access 2010, so I do not expect that to be an issue.

Can you create a small sample data set that returns this problem and post it here?
Then I will recreate your exact data and see what happens on my side.
 
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