473,382 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Running Count in Query - over multiple years

Hi all,
I am working on a document control database where I have a table
"tblControl" containing two columns "DocID" and "SchIssueDate".
"DocID" is the key field with text format while "SchIssueDate" is Date
format.

I am trying to create a S-Curve for the documents to be issued each
month to show the required progress. I have made this query for this:

SELECT Format([SchIssueDate],"mmm-yyyy") AS [Month],
DatePart("yyyy",[SchIssueDate]) AS AYear, DatePart("m",[SchIssueDate])
AS AMonth, DCount("DocID","tblControl","DatePart('m',
[SchIssueDate])<=" & [AMonth] & " And DatePart('yyyy',
[SchIssueDate])<=" & [AYear] & " ") AS RunTot
FROM tblControl
GROUP BY Format([SchIssueDate],"mmm-yyyy"),
DatePart("yyyy",[SchIssueDate]), DatePart("m",[SchIssueDate])
ORDER BY DatePart("yyyy",[SchIssueDate]), DatePart("m",[SchIssueDate]);

This works fine for one year progress. i.e. the DCount keeps counting
Documents till December. But then for January of next year it drops
the count back bacause of [SchIssueDate])<=" & [AMonth]... the AMonth
value is 1.

Here is what I get:

Month AYear AMonth RunTot
Jun-2006 2006 6 1
Nov-2006 2006 11 5
Dec-2006 2006 12 16
Jan-2007 2007 1 19
Feb-2007 2007 2 31
Mar-2007 2007 3 34
Apr-2007 2007 4 88
May-2007 2007 5 226
Jun-2007 2007 6 537
Jul-2007 2007 7 746
Aug-2007 2007 8 917
Sep-2007 2007 9 1166
Oct-2007 2007 10 1481
Nov-2007 2007 11 1685
Dec-2007 2007 12 1870
Jan-2008 2008 1 287 (- Dcount fails here to display running count)
Feb-2008 2008 2 380
Mar-2008 2008 3 391

Would greatly appreciate if anyone can suggest a solution?

Regards,
Vikas

Dec 19 '06 #1
1 6762
Vikas,

I don't have experience with the dcount-function, but I suppose the
and-condition in the comparison is fatal. I rather woud try something
like "between ""2006-01"" and format(schIssueDate,""yyyy-mm"")", but
more in general I probably would avoid dcount en I would use the
standard count-function using a calendar-table containing dates used
for intervals and joining this with a non-equi-join expression like
"format(tblControl.schIssueDate,"yyyy-mm"),count(*) where
tblControl.schIssueDate >= #2006/01/01# and tblControl.schIssueDate <=
calendar.monthstart and calendar.monthstart between '2006-01-01# and
#2008-01-01# group by format(tblControl.schIssueDate,"yyyy-mm");" or
some other interval.
The non-equijoin expression cannot be specified using connection-lines
in the design-window of the query-editor but could be specified
implicitly in field conditions or the sql-window using explicit
join-syntax. I did not test this, but I am pretty sure a working
solution should always be possible this way using standard
sql-constructs.

Vikas schreef:
Hi all,
I am working on a document control database where I have a table
"tblControl" containing two columns "DocID" and "SchIssueDate".
"DocID" is the key field with text format while "SchIssueDate" is Date
format.

I am trying to create a S-Curve for the documents to be issued each
month to show the required progress. I have made this query for this:

SELECT Format([SchIssueDate],"mmm-yyyy") AS [Month],
DatePart("yyyy",[SchIssueDate]) AS AYear, DatePart("m",[SchIssueDate])
AS AMonth, DCount("DocID","tblControl","DatePart('m',
[SchIssueDate])<=" & [AMonth] & " And DatePart('yyyy',
[SchIssueDate])<=" & [AYear] & " ") AS RunTot
FROM tblControl
GROUP BY Format([SchIssueDate],"mmm-yyyy"),
DatePart("yyyy",[SchIssueDate]), DatePart("m",[SchIssueDate])
ORDER BY DatePart("yyyy",[SchIssueDate]), DatePart("m",[SchIssueDate]);

This works fine for one year progress. i.e. the DCount keeps counting
Documents till December. But then for January of next year it drops
the count back bacause of [SchIssueDate])<=" & [AMonth]... the AMonth
value is 1.

Here is what I get:

Month AYear AMonth RunTot
Jun-2006 2006 6 1
Nov-2006 2006 11 5
Dec-2006 2006 12 16
Jan-2007 2007 1 19
Feb-2007 2007 2 31
Mar-2007 2007 3 34
Apr-2007 2007 4 88
May-2007 2007 5 226
Jun-2007 2007 6 537
Jul-2007 2007 7 746
Aug-2007 2007 8 917
Sep-2007 2007 9 1166
Oct-2007 2007 10 1481
Nov-2007 2007 11 1685
Dec-2007 2007 12 1870
Jan-2008 2008 1 287 (- Dcount fails here to display running count)
Feb-2008 2008 2 380
Mar-2008 2008 3 391

Would greatly appreciate if anyone can suggest a solution?

Regards,
Vikas
Dec 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Christopher Brandsdal | last post by:
Hi! I have a problem running my code on 2000 server and iis5.0. The code runs perfectly on my localhost (xp iis5.1) but when i run it on 2000 server iis5.0 I get this error: ...
7
by: Schraalhans Keukenmeester | last post by:
X-Followup: comp.lang.php I have a PHP script that adds messages to a simple MySQL Database. (PHP 5.0.3, MySQL 4.1.1) One of the fields it stores is msgid. The new msgid is a count of all...
5
by: Terri | last post by:
I have a form with a multi-select combo. I dynamically build a SELECT statement, open a report, and set the recordsource to my dynamic SELECT statement. I count the records returned in the report...
1
by: jnikle2100 | last post by:
I have a simple database comprised of two tables. tbl_employee_info stores employee info (name, hire date, title, etc.) and tbl_departmental_history stores departmental transfer history. The two...
9
by: turtle | last post by:
I need my running sum to work for more than one year. It works great but then starts over when the year starts over. My example here is straight from the Northwind database. I want a runningg sum...
2
by: cefrancke | last post by:
I can't seem to find a straight answer for my specific issue. Any help would be appreciated. I would like to count the various items in a table where the fields have a 'group' relationship. I...
2
by: pierrelap | last post by:
Hello, I need to code a query that: 1-counts the number of time two companies have been in a deal together 2-in the five years that preceded the deal Lead Participant DealDate AAA BBB ...
1
by: heckstein | last post by:
I am working in Access 2002 and trying to create a report from our company's learming management system. I am not a DBA and most of my SQL knowledge has been self taught through trial and error. I...
1
by: nospam | last post by:
I have a report to count some statistics of case data. I can't figure out how to make Access group and sum/count information to give me a nice statistics report. Basically the database has case...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.