ACC2000: How to Create a Top Values Per Group ReportID: Q208822
|
This article demonstrates how you can create a report that ranks a specific number of records for each group in order according to a top value, for example, the top five selling products per category.
Microsoft Access has a TopValues property that you can use in a query to return a specific number (N) or a specified percentage (N%) of records. By using a main/sub report with a query that has a value set for its TopValues property, you can create a report listing the top N records for each group.
To create a top values per group report, follow these steps:
Query: Top_N_Products
-------------------------------------------------------------------
Type: Select Query
Join: Order Details.[ProductID] <-------> Products.[ProductID]
TopValues: 5
Field: CategoryID
Table: Products
Total: Group By
Criteria: [Reports]![Top_N_Per_Group]![CategoryID]
Field: ProductName
Table: Products
Total: Group By
Field: SaleAmount: Sum([Order Details].[UnitPrice]*[Quantity])
Total: Expression
Sort: Descending
NOTE: Referencing the CategoryID from the Top_N_Per_Group report as
criteria ensures that this query filters records by CategoryID before
it applies the TopValues property to the recordset.For more information about the TopValues property, click Microsoft Access Help on the
Help menu, type "TopValues Property" in the Office Assistant or the Answer Wizard,
and then click Search to view the topics returned.
Additional query words:
Keywords : kbusage kbdta RptOthr
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: June 10, 1999