Great to see the Lounge again!
I am trying to work out how to count the number of instances of the same date returned in a crosstab query for a report. We run a clinic once (sometimes twice) per week, in which we see around four to six patients. I need to count the number of clinics run per month (which I will then show on a report along with the average number of patients seen per clinic).
Can anyone point me in the right direction as to how this is done?
Many thanks,
Van
count number of same dates
-
- 2StarLounger
- Posts: 114
- Joined: 28 Sep 2010, 21:13
- Location: Melbourne, Oz
-
- 3StarLounger
- Posts: 390
- Joined: 26 Jan 2010, 16:02
- Location: Las Vegas, NV
Re: count number of same dates
I see that our guru, Hans, is away for a while so I'll attempt to provide an example of an application I wrote several years ago that contains cross tab reports. See attached. I wrote the cross-tab reports with a lot of Hans' help.
Click on Reports Submenu. Try running any of the reports (with the exception of the one entitiled "General Query ..."). If you use start and end dates of 1/1/2010 and 12/31/2010, you should see data in the reports.
There's a lot of VBA code behind the reports.
Is this what you're looking for?
Click on Reports Submenu. Try running any of the reports (with the exception of the one entitiled "General Query ..."). If you use start and end dates of 1/1/2010 and 12/31/2010, you should see data in the reports.
There's a lot of VBA code behind the reports.
Is this what you're looking for?
You do not have the required permissions to view the files attached to this post.
Carol W.
-
- 2StarLounger
- Posts: 114
- Joined: 28 Sep 2010, 21:13
- Location: Melbourne, Oz
Re: count number of same dates
Hi Carol,
Thanks for the reply. It's not quite what i'm after though. I understand how to use parameters to return dates in the chosen range. What I want to do is then count the total number of dates returned....but count unique instances only. For example, if the query returns the dates:
1/1/10
1/1/10
2/1/10
3/1/10
the count of unique dates would be 3.
Regards,
Van
Thanks for the reply. It's not quite what i'm after though. I understand how to use parameters to return dates in the chosen range. What I want to do is then count the total number of dates returned....but count unique instances only. For example, if the query returns the dates:
1/1/10
1/1/10
2/1/10
3/1/10
the count of unique dates would be 3.
Regards,
Van
-
- 2StarLounger
- Posts: 112
- Joined: 25 Jan 2010, 20:19
Re: count number of same dates
The SQL would be:
SELECT Count(Dates) AS DateCount FROM (select distinct dateField as dates from tbldates) as GrpDates
or
SELECT Count(Dates) AS dateCount FROM (select dateField as dates from tblDates group by dateField) as GrpDates
The second SQL would be created by using queries in the following manner:
A query with a single field(the date field) grouped on that filed (GrpDates in the attached)
Use that query as the source of a second query grouped on the date field with an operator of Count (qryFinal in the attached)
The attached shows the three methods
SELECT Count(Dates) AS DateCount FROM (select distinct dateField as dates from tbldates) as GrpDates
or
SELECT Count(Dates) AS dateCount FROM (select dateField as dates from tblDates group by dateField) as GrpDates
The second SQL would be created by using queries in the following manner:
A query with a single field(the date field) grouped on that filed (GrpDates in the attached)
Use that query as the source of a second query grouped on the date field with an operator of Count (qryFinal in the attached)
The attached shows the three methods
You do not have the required permissions to view the files attached to this post.
-
- 3StarLounger
- Posts: 390
- Joined: 26 Jan 2010, 16:02
- Location: Las Vegas, NV
Re: count number of same dates
I think I see what you want. See attached sample database.
The query called qrycount returns 3, using your example dates in tbltest. qrycount is based on qrytest which, in turn, is based on tbltest.
Hope this is clear.
The query called qrycount returns 3, using your example dates in tbltest. qrycount is based on qrytest which, in turn, is based on tbltest.
Hope this is clear.
You do not have the required permissions to view the files attached to this post.
Carol W.
-
- 2StarLounger
- Posts: 114
- Joined: 28 Sep 2010, 21:13
- Location: Melbourne, Oz
Re: count number of same dates
thanks mbarron, that's just what i'm after. i'll give it a go.
regards,
van
regards,
van
-
- 2StarLounger
- Posts: 114
- Joined: 28 Sep 2010, 21:13
- Location: Melbourne, Oz
Re: count number of same dates
thanks Carol. that works well.
regards
Van
regards
Van
-
- Administrator
- Posts: 78583
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands