As a follow on to my prior post, I was able to develop a report that compares data from our Kids Summer Feeding program between 2 years. However the report takes over 4 minutes to run.
The primary table containing the data is "Site Weekly Counts". There is 1 record for each week of the program for each Site containing 11 fields relating to quantities of meals delivered and served. A typical running of the report is done off the Reports Menu which can be opened from either the Main Menu or the Site Weekly Counts form. On the Reports Menu, the first program to compare is the Selected Program near the top of the menu. The report weeks to include for that program are selected next. Below, next to the Year to Year Comparison button that runs the report, Program 2 and its weeks are selected. Right now there is data from last year (2017) and a bit of test data for 2018.
The method I ended up using was to first determine if a site had data for each program and then add 2 "IIf"expressions in a query for each of the 11 quantity fields representing each of the 2 programs to be compared. The IIf expressions add the source value if the year matches. This is done through the following queries:
- Yrly Compare Query Prog1 Sites and Yrly Compare Query Prog2 Site are summary queries that provide a target for the next group of queries DLookup. They are a list of the site names that have data in each program along with the program year.
- The following queries are input one to the next in the order listed and result in a record source for the report:
- Yrly Compare Query All Data Sub1 is the initial query that gathers all the data from the Sites, Site Weekly Counts and Citys County tables. It has criteria to select only the weeks indicated in the Reports Menu for each program. It also has the DLookup expressions to both the Yrly Compare Query Progn Site queries filling in the year if there is a match.
- Yrly Compare Query All Data Detail adds criteria to select sites based on which of the 5 Sites to Include options is selected. This has to do with whether a site participated in both programs or just one using the DLookup results from the prior query.
- Yrly Compare Query All Data adds criteria to limit to the County selected if the first Counties Option is selected in the Reports Menu. And it has the 2 sets of IIf expressions to add the value from the source field if the record's year matches the Program year. Here's an example: "Prog1Deliv: IIf([Year]=[Prog1Yr],[Delivered],0)".
- Yrly Compare Query All Data Input to Make Tble Qry creates a temporary table (Yrly Compare Details Rpt Input) that is the record source for the report and the sub report that has the totals.
The report then takes the two sets expression fields created in query 3 and summarizes them by Meal Type and Site. The Program 1 fields are in a row under the Program 2 fields row. Text Box fields in the report then subtract the Program2 fields from the Program 1 fields for the Change row.
I timed the report run locally on my PC at around 4.5 minutes. The queries on their own run quickly as they normally do. So it's the report that takes the excess time. I tried and compared doing the summaries in the query vs. the report but then the queries took a long time.
The database is attached but you will need to re-link the tables.
I'd appreciate any thoughts as to how this report might be done to improve the run time.
Thanks.