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.
 
Thanks, Xenou-

1) there are not any NewCert records (that distinction started this year and we may have some come in next week) - but that's why I'm confused about the 1s in the months for Feb-Nov. I did not take out any records.
2) the start dates are reliable, I just created those thinking about translating "1" to "January" and "2" to "February" etc. If there's some other way to do that, I'll take that suggestion to, especially if it may be the cause of those pesky 1s.
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I had to remove the names and emails because of security (is that okay?)
That is fine (and recommended, we don't want to post anyone's real information!).;)
Those fields are not important to the query anyway.

So I copied your data and queries, and here is what I got:
YearMonthNumberMonthNameExamRegistCountNewExamRegistCountOldExamRegistCountRecert
20171January0561
20172February000
20173March000
20174April000
20175May000
20176June000
20177July000
20178August000
20179September000
201710October000
201711November000
201712December010

<tbody>
</tbody>

which is what I would suspect. I do not understand why you are getting different results (I cannot seem to reproduce it). Its really odd because the calculation is set up in exactly the same manner for those other two which seem to work fine.

Do we a favor and trying add a Recert or OldCred record for the month of June. Does the one in the NewCred line for June go away when a number is put in one of those other two columns? I am just trying to determine if the pattern is that all months will no data seem to get a one put in that first column.

A question regarding the MonthNumber and Year fields we are joining on. Are they set up as numbers in both tables? Or is one or both Text?
 
Last edited:
Upvote 0
So, I can't add a record to our database (at this time), so I took the "BOGExam-Registered" query, made a table, then manually entered in the following row (for a total of 59):

ID
LAST_FIRSTEMAILMEMBER_TYPEACTIVITY_TYPEPRODUCT_CODEDESCRIPTIONStartDateINDICATORMonthYear
123456MCREYNOLDS, CLIFTONemail@email.comMEMBBOGEXAMBOGHM
6/15/2017Recert62017

<tbody>
</tbody>


I adjusted the query to reflect the table name:

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 INNER JOIN [Exam-Registered-DeleteLater] ON (MonthLookup.Year = [Exam-Registered-DeleteLater].Year) AND (MonthLookup.MonthNumber = [Exam-Registered-DeleteLater].Month)
GROUP BY MonthLookup.Year, MonthLookup.MonthNumber, MonthLookup.MonthName
ORDER BY MonthLookup.Year, MonthLookup.MonthNumber;


And got this as a result:
YearMonthNumberMonthNameExamRegistCountNewExamRegistCountOldExamRegistCountRecert
20171January0561
20176June001
201712December010

<tbody>
</tbody>

Which is closer to what I want - but I'd "like" the months to stay there, but say 0 across. Is this fixed because I queried a table instead of another query?
 
Upvote 0
Which is closer to what I want - but I'd "like" the months to stay there, but say 0 across. Is this fixed because I queried a table instead of another query?
No, look at your query again. When you adjusted it, you changed it from a LEFT JOIN to an INNER JOIN.
Remember, you must make it a LEFT JOIN to show all the records from your MonthLookup table.
 
Upvote 0
Yep - I caught that join change apparently the same time.

So, I did get the table I want:
YearMonthNumberMonthNameExamRegistCountNewExamRegistCountOldExamRegistCountRecert
20171January0561
20172February000
20173March000
20174April000
20175May000
20176June001
20177July000
20178August000
20179September000
201710October000
201711November000
201712December010

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


But does this mean the table vs query argument is it?
 
Upvote 0
But does this mean the table vs query argument is it?
Possibly. It is pretty rare, but I did come across an instance once in SQL where I was getting unexpected results. I was using multiple layers of queries, and I was getting errors because of invalid data. That data was being weeded out by the first query in line, but a query doing a calculation done the line was returning the error. It shouldn't have been, because the bad data was already weeded out by then. But then I learned that when you submit the query (which depends on other queries), SQL determine what the most efficient way of doing so is, so it may restructure things behind the scenes. I wonder if something like this may be what is going on...

Like I said, it is pretty rare. I have only come across that once in about 17 years.

One workaround would be to write your query to a table, and then work off of that. That obviously is not ideal...
 
Last edited:
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