Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Query to get cumulative data

Posted on 2011-03-25
19
Medium Priority
?
726 Views
Last Modified: 2013-11-29
Hello,

I have a table with the following structure, this is in MS Access 2007.

TicketNumber  Date
2343               01/01/2011
1234               01/02/2011
3422               01/4/2011
3423               01/4/2011
7423               02/4/2011
3523               02/6/2011
3513               02/6/2011
3923               03/4/2011

I am able to create a crosstab that would add up the NUMBER of tickets per date; then I take generate a graph using the cross tab and I get a nice simple bar chart displaying tickets/month, so, Jan - 4, Feb - 3, March  - 1

My question now is, I would like to GRAPH a cumulative chart,

It will display, 4 tickets for Jan, 4+3 tickets for Feb, and 4+3+1 tickets for March.

Thanks,
0
Comment
Question by:babble324
  • 9
  • 6
  • 4
19 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35218328
select sum(iif(month(date)<2,1,0)) as Jan,sum(iif(month(date)<3,1,0)) as Feb,sum(iif(month(date)<4,1,0)) as Mar
from table
0
 

Author Comment

by:babble324
ID: 35219185
I need this done for years worth of data.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35219274
how do you want the result look like?
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

Author Comment

by:babble324
ID: 35219294
Jan --4
Feb --7
Mar --8
etc.
etc.

This will then be charted on al ine graph using Access Graph Objects.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35219307
did you try the query posted above?
0
 

Author Comment

by:babble324
ID: 35220130
This will only work for 3 months. I need this for years' worth of data.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35220230
then expand the query.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 35223771
@babble324

should a month's cumulative sum be for all prior months or just the prior months in that calendar year?
0
 

Author Comment

by:babble324
ID: 35224136
All months that are in the query. Also note that some months may not be there, I.e no tickets issued in that month. So I just want a tally of whatever was queried. Thank you so much for your help.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 35224241
I made a CumulativeSumProblem table and populated it with your posted data.

SELECT Year([TicketDate])*100+Month([TicketDate]) AS yyyymm, Count(CumulativeSumProblem.TicketNumber) AS CountOfTicketNumber, 
(Select Count(*) From CumulativeSumProblem As CS Where Year(CS.[TicketDate])*100+Month(CS.[TicketDate]) <= Year(CumulativeSumProblem.[TicketDate])*100+Month(CumulativeSumProblem.[TicketDate]) ) As CumulativeSum
FROM CumulativeSumProblem
GROUP BY Year([TicketDate])*100+Month([TicketDate]);

Open in new window

0
 

Author Comment

by:babble324
ID: 35224725
yep, that's exactly what i want.

Now, under the yyyymm field in the query, is there a way it can be formatted differently? basically, i would like to take this data and feed it into a ms access chart, it's not recognizing "201103" as a date.

Thanks again,


0
 
LVL 46

Expert Comment

by:aikimark
ID: 35226033
I guess you might try changing all these date values into the first of the month.

So this:
Year([TicketDate])*100+Month([TicketDate])

Open in new window


becomes this
DateSerial(Year([TicketDate]), Month([TicketDate], 1)

Open in new window

0
 

Author Comment

by:babble324
ID: 35226479
I get wrong number of arguments.


SELECT DateSerial(Year([TicketDate]), Month([TicketDate], 1)) AS yyyymm, Count(CumulativeSumProblem.TicketNumber) AS CountOfTicketNumber, 
(Select Count(*) From CumulativeSumProblem As CS Where Year(CS.[TicketDate])*100+Month(CS.[TicketDate]) <= Year(CumulativeSumProblem.[TicketDate])*100+Month(CumulativeSumProblem.[TicketDate]) ) As CumulativeSum
FROM CumulativeSumProblem
GROUP BY DateSerial(Year([TicketDate]), Month([TicketDate], 1));

Open in new window

0
 
LVL 46

Expert Comment

by:aikimark
ID: 35226565
it is a typo on my part.  there is a misplaced right parenthesis
DateSerial(Year([TicketDate]), Month([TicketDate]), 1)

Open in new window

0
 

Author Comment

by:babble324
ID: 35226591
It now says:

"You tried to execute a query that does not include the specified expression 'TicketDate' as part of an aggregate function"
0
 
LVL 46

Expert Comment

by:aikimark
ID: 35226627
please check that you corrected all instances of the typo.  If you still get the error message, then please post your SQL.
0
 

Author Comment

by:babble324
ID: 35226648
There you go.

SELECT DateSerial(Year([TicketDate]), Month([TicketDate]), 1) AS yyyymm, Count(CumulativeSumProblem.TicketNumber) AS CountOfTicketNumber, 
(Select Count(*) From CumulativeSumProblem As CS Where Year(CS.[TicketDate])*100+Month(CS.[TicketDate]) <= Year(CumulativeSumProblem.[TicketDate])*100+Month(CumulativeSumProblem.[TicketDate]) ) As CumulativeSum
FROM CumulativeSumProblem
GROUP BY DateSerial(Year([TicketDate]), Month([TicketDate]), 1);

Open in new window

0
 
LVL 46

Accepted Solution

by:
aikimark earned 2000 total points
ID: 35226663
you didn't make enough corrections.
SELECT DateSerial(Year([TicketDate]), Month([TicketDate]), 1) AS yyyymm, Count(CumulativeSumProblem.TicketNumber) AS CountOfTicketNumber, 
(Select Count(*) From CumulativeSumProblem As CS Where 
DateSerial(Year(CS.[TicketDate]), Month(CS.[TicketDate]), 1) <= DateSerial(Year(CumulativeSumProblem.[TicketDate]), Month(CumulativeSumProblem.[TicketDate]), 1) ) As CumulativeSum
FROM CumulativeSumProblem
GROUP BY DateSerial(Year([TicketDate]), Month([TicketDate]), 1);

Open in new window

0
 

Author Comment

by:babble324
ID: 35226679
Thank you very much. It worked!

0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question