Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cumulative Totals Query

Status
Not open for further replies.

jmob

Programmer
Jun 21, 2005
58
US
I am trying to make a cumulative query to use in a pivotChart.
I have a query with this data already:
Date1 Date2 Est Actual | I want:
1/2/05 1/3/05 3 4 | 3 4
1/3/04 1/4/04 4 6 | 7 10
1/1/03 1/1/03 2 2 | 9 12
Date1, and Date2 are Descending order.
I would like to create a running total for the Est, and Actual columns.
I have looked at many threads, but I haven't found any to help me. Thanks.
 
Try this
Code:
Select Date1, Date2, 
       
       (Select SUM(Est) From tbl Where tbl.Date2 >= T.Date2) As EstSum,

       (Select SUM(Actual) From tbl Where tbl.Date2 >= T.Date2) As ActSum

From tbl As T

Order By 2;
WARNING: It will probably run like a dog because you are doing so much computation on every record.
 
How can I include the date columns as well? It is blanking them out. The cumulative sum works great though! Thanks.
 
Select Date1, Date2,

You aren't seeing these? Are those the correct names for the columns?
 
I was quering a query. I think that was causing problems for those fields not to show up. I'll fix that
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top