ntcameron
01-28-2010, 02:02 PM
I am making a report that should be displaying the top 25 associates in each of 40 regions. Each region can have thousands of associates. I want to have 40 pages, one for each district with 20-25 associates per page.
So far I am grouping by district and then sorting by the stat we are measuring in descending order. I want to limit this to the top 20-35 per district. Thanks for any help!
Galaxiom
01-28-2010, 02:07 PM
Edit the record source query by adding TOP 30 just after the select.
SELECT TOP 30 fieldname, fieldname2 etc
ntcameron
01-28-2010, 02:52 PM
So if I want the top 20 of a calculated field called UPT for each District I would do:
SELECT TOP 20 UPT, District, ....other fields
Is that correct?
Galaxiom
01-28-2010, 03:51 PM
The fields can be listed in any order.
TOP 20 just gives the first 20 records. Order By the field you want to define the first 20.
ntcameron
01-28-2010, 04:15 PM
The problem i have is that I need more then just the first 20. Out of a table with thousands of records, I need the first 20 of one district. Then there could be another 1000 rows, then I need the top 20 out of the next district, so on for 40 districts.
I might need some other coding to accomplish this? Or if there is a way to limit results in a report page in access I could do that as well.
Galaxiom
01-28-2010, 05:21 PM
Use the TOP modifier in subqueries with WHERE conditions for each district.
However this is going to be a very large query to write with forty districts. It could be generated using a VBA loop but first get it working with a couple of districts.
ntcameron
01-29-2010, 05:53 AM
Thanks for the help. I was thinking it may be more efficient to run things in loop but I am not that familiar with VBA being new to Access. Good learning opportunity though! Thanks again