ACC2: How to Create Running Totals in a QueryID: Q132134
|
Moderate: Requires basic macro, coding, and interoperability skills.
This article demonstrates two methods you can use to create a running
totals query; that is, the total for each record is a summation of that
record and any previous records. This type of query is useful for
displaying cumulative totals over a group of records (or over a period of
time) in a graph or report.
Field: AYear: DatePart("yyyy",[Order Date])
Total: Group By
Sort: Ascending
Show: Yes
Field: AMonth: DatePart("m",[Order Date])
Total: Group By
Sort: Ascending
Show: Yes
Field: RunTot: DSum("Freight","Orders","DatePart('m', _
[Order Date])<=" & [AMonth] & " And DatePart('yyyy', _
[Order Date])<=" & [AYear] & "")
Total: Expression
Show: Yes
Field: FDate: Format([Order Date],"mmm")
Total: Group By
Sort: Ascending
Show: Yes
Field: DatePart("yyyy",[Order Date])
Total: Where
Criteria: 1991
Show: No
AYear AMonth RunTot FDate
--------------------------------
1991 5 514.17 May
1991 6 1225.75 Jun
1991 7 2133.33 Jul
1991 8 3041.5 Aug
1991 9 4052.12 Sep
1991 10 7345.04 Oct
1991 11 8140.26 Nov
1991 12 8933.32 Dec
Field: EmpAlias: Employee ID
Total: Group By
Show: Yes
Field: Freight
Total: Sum
Show: Yes
Field: RunTot: Format(DSum("Freight","Orders","[Employee ID]<=" _
& [EmpAlias] & ""),"$0,000.00")
Total: Expression
Show: Yes
EmpAlias SumOfFreight RunTot
------------------------------------
1 $10,450.91 $10,450.91
2 $10,694.25 $21,145.16
3 $13,347.13 $34,492.29
4 $14,046.90 $48,539.19
5 $4,352.02 $52,891.21
6 $4,344.71 $57,235.92
7 $7,967.62 $65,203.54
8 $10,084.86 $75,288.40
9 $3,918.26 $79,206.66
For more information about a totals query, search for "queries: calculations," and then "Calculating Totals in a Query" using the Microsoft Access Help menu.
Keywords : kbusage QryTotal
Version : 2.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 20, 1999