Date Calculation in Query, Previous Week Calculations

elephant97

Board Regular
Joined
Sep 18, 2002
Messages
63
Let me start off with the data set first, all in one table:

Name--------Date----Metric_1------Metric_2
John--------7/1/04-----11------------21
Tom--------7/8/04-----88------------99
John--------7/8/04-----103----------104

Here are my needs for a query:
1) When a name is selected, report only the 2 most recent metrics for that name in separate fields
2) When a name is selected, compile the previous 13 entries of the metric and take an average. So, under metric_1 there would be an avg of the last 13 weeks. Under metric_2, an average of the last 13 weeks, etc.

Hope that isn't too complicated. Thanks for the help!!!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
1)
Filter the query by the name you wish to report, you can use the builder to take criteria from a text box on a form which is useful for this sort of thing.
Sort the query by the date field in descending order.
In the Queries property sheet set the Top Values to 2.

2)
I would do this in 2 steps, first create and save a query the same as above but with the top values set to 13

create a new query based on the above query but leaving out the dates. Turn this into a Totals Query (Button on toolbar)
then in the Totals row select Avg under your metrics.

HTH

Peter
 
Upvote 0

Forum statistics

Threads
1,221,783
Messages
6,161,940
Members
451,730
Latest member
BudgetGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top