Cumulative sum in query

J

Jean-Marie

I am building a database to manage a fleet of transport
vehicles. My system is Access 2000/Win XP Pro.
I have among other tables
- tblVehicles (LicensePlate (PK), ChassisNo, AcqDate,
HorsePower, MotorType),
- tblRevenue (IDRevenue, DateRev, AmountRev, VehicleRev,
DriverRev, CommentRev).
I have built a query that displays the summary revenue
per week for a given vehicle, something looking like this.
----------------------------------
Week # Revenue
Week1 Rev1
Week2 Rev2
..... ....
Weekn Revn
-----------------------------------

Now I need to build another one that gives the cumulative
revenue per week, something like the following
--------------------------------------------
Week # Revenue
Week1 Rev1
Week2 Rev1+Rev2
..... ....
Weekn Rev1+Rev2+ . +Revn
-------------------------------------------------
I don't know how to get there. Can someone help me,
please?

Tanks in advance and Merry Christmas

Jean-Marie.
 
M

Marshall Barton

Jean-Marie said:
I am building a database to manage a fleet of transport
vehicles. My system is Access 2000/Win XP Pro.
I have among other tables
- tblVehicles (LicensePlate (PK), ChassisNo, AcqDate,
HorsePower, MotorType),
- tblRevenue (IDRevenue, DateRev, AmountRev, VehicleRev,
DriverRev, CommentRev).
I have built a query that displays the summary revenue
per week for a given vehicle, something looking like this.
----------------------------------
Week # Revenue
Week1 Rev1
Week2 Rev2
.... ....
Weekn Revn
-----------------------------------

Now I need to build another one that gives the cumulative
revenue per week, something like the following
--------------------------------------------
Week # Revenue
Week1 Rev1
Week2 Rev1+Rev2
.... ....
Weekn Rev1+Rev2+ . +Revn
-------------------------------------------------


I think this the kind of query you're looking for:

SELECT [Week#],
(SELECT Sum(Q.[Revenue])
FROM query1 As Q
WHERE Q.[Week#] <= query1.[Week#]
) As CumRevenue
FROM query1

But, this is even easier to do in a report base on the first
query and settin the Revenue text box's RunningSum property
to Over All.
 
J

Jean-Marie

Thanks Marshal.

I will test your advice and let you know how it went.
I need the query because I will then base on it a chart
representing the cumulative revenue as against the week
numbers.
Thanks again.

-----Original Message-----
Jean-Marie said:
I am building a database to manage a fleet of transport
vehicles. My system is Access 2000/Win XP Pro.
I have among other tables
- tblVehicles (LicensePlate (PK), ChassisNo, AcqDate,
HorsePower, MotorType),
- tblRevenue (IDRevenue, DateRev, AmountRev, VehicleRev,
DriverRev, CommentRev).
I have built a query that displays the summary revenue
per week for a given vehicle, something looking like this.
----------------------------------
Week # Revenue
Week1 Rev1
Week2 Rev2
.... ....
Weekn Revn
-----------------------------------

Now I need to build another one that gives the cumulative
revenue per week, something like the following
--------------------------------------------
Week # Revenue
Week1 Rev1
Week2 Rev1+Rev2
.... ....
Weekn Rev1+Rev2+ . +Revn
-------------------------------------------------


I think this the kind of query you're looking for:

SELECT [Week#],
(SELECT Sum(Q.[Revenue])
FROM query1 As Q
WHERE Q.[Week#] <= query1.[Week#]
) As CumRevenue
FROM query1

But, this is even easier to do in a report base on the first
query and settin the Revenue text box's RunningSum property
to Over All.
 
J

Jean-Marie

I tested it and worked perfect.

Many thanks again.

Jean-Msarie
-----Original Message-----
Thanks Marshal.

I will test your advice and let you know how it went.
I need the query because I will then base on it a chart
representing the cumulative revenue as against the week
numbers.
Thanks again.

-----Original Message-----
Jean-Marie said:
I am building a database to manage a fleet of transport
vehicles. My system is Access 2000/Win XP Pro.
I have among other tables
- tblVehicles (LicensePlate (PK), ChassisNo, AcqDate,
HorsePower, MotorType),
- tblRevenue (IDRevenue, DateRev, AmountRev, VehicleRev,
DriverRev, CommentRev).
I have built a query that displays the summary revenue
per week for a given vehicle, something looking like this.
----------------------------------
Week # Revenue
Week1 Rev1
Week2 Rev2
.... ....
Weekn Revn
-----------------------------------

Now I need to build another one that gives the cumulative
revenue per week, something like the following
--------------------------------------------
Week # Revenue
Week1 Rev1
Week2 Rev1+Rev2
.... ....
Weekn Rev1+Rev2+ . +Revn
-------------------------------------------------


I think this the kind of query you're looking for:

SELECT [Week#],
(SELECT Sum(Q.[Revenue])
FROM query1 As Q
WHERE Q.[Week#] <= query1.[Week#]
) As CumRevenue
FROM query1

But, this is even easier to do in a report base on the first
query and settin the Revenue text box's RunningSum property
to Over All.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Totals on crosstab 6
Dynamically filtering a report 5

Top