![]() The second method uses a totals query with a DSum() function to create a running total over a group. Note that the RunTot field displays the following records with a running sum: AYear AMonth RunTot FDate The expression in the Field box filters the query's recordset to include data from 1997 only. In the fifth column of the query design grid, type the following expression in the Field box, and make the following selections for the Total, Criteria, and Show boxes: Field: DatePart("yyyy",) The expression in the Field box displays each month in a textual format, such a Jan, Feb, Mar, and so on. In the fourth column of the query design grid, type the following expression in the Field box, and make the following selections for the Total, Sort, and Show boxes: Field: FDate: Format(,"mmm") The expression in the Field box uses the DSum() function to sum the Freight field when the values in both the AMonth and the AYear fields are less than or equal to the current record that the query is processing. ![]() Field: RunTot: DSum("Freight","Orders","DatePart('m', _ Remove the underscore from the end of the line when re-creating this example. NOTE In the following example, an underscore (_) at the end of a line is used as a line-continuation character. In the third column of the query design grid, type the following expression in the Field box, and make the following selections for the Total and Show boxes. The expression in the Field box sorts and displays the month portion of the Order Date field as an integer value from 1 to 12. In the second column of the query design grid, type the following expression in the Field box, and make the following selections for the Total, Sort, and Show boxes: Field: AMonth: DatePart("m",) The expression in the Field box displays and sorts the year portion of the OrderDate field. In the first column of the query design grid, type the following expression in the Field box, and make the following selections for the Total, Sort, and Show boxes: Field: AYear: DatePart("yyyy",) Note In Access 2007, click Totals in the Show/Hide group on the Design tab. To create and run this query, follow these steps:Ĭreate a new select query and add the Orders table. Because the DSum function runs once for every record in the query, it may take several seconds (depending on the speed of your computer) for the query to finish processing. The sample data is limited to one year for performance reasons. The following sample query uses the Orders table from the sample database Northwind to create a running sum of the freight costs for each month in 1997. When the query moves to the next record, the DSum function runs again and updates the cumulative total. The DSum function sums the current record and any previous records. ![]() ![]() The first method uses a DSum function and criteria in a query to create a running sum over time. Note You can see a demonstration of the technique that is used in this article in the sample file Qrysmp00.exe. 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. A running totals query is a query in which the total for each record is a summation of that record and any previous records. This article demonstrates two methods that you can use to create a running totals query. This article applies to a Microsoft Access database (.mdb) file or to a Microsoft Access database (.accdb) file. Advanced: Requires expert coding, interoperability, and multiuser skills.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |