Solved

How do I calculate average based on a dynamic date

Posted on 2011-09-05
3
180 Views
Last Modified: 2012-05-12
I have a spreadsheet with the following layout.

       06/06/2011      13/06/2011      20/06/2011      27/06/2011      04/07/2011      11/07/2011
Line 1      114      200      980      879      675      600
Line 2      78      50      333      89      32      23
Total      2281      2294      2147      1906      2254      2043

On a new worksheet I want to be able to calculate the past 4 weeks average for each line,
 based on the date the user enters.

Eg if I enter 11/07/2011 in the below cell I want the average to be calculated for Line 1 and Line 2.

11/07/2011
Line 1      (fomula here to calc avg of 04/07/2011 to 13/06/2011)
Line 2      (fomula here to calc avg of 04/07/2011 to 13/06/2011)
0
Comment
Question by:JAK11
3 Comments
 
LVL 50

Accepted Solution

by:
barry houdini earned 250 total points
ID: 36486175
You can use AVERAGEIFS function, something like this

=AVERAGEIFS(Data!A2:Z2,Data!A$1:Z$1,">="&D$2-28,Data!A$1:Z$1,"<="&D$2-7)

where D2 is your date and in Data sheet row 1 has the dates and row 2 has your "Line 1" data. Repeat for line 2 (just drag formula down a line)

regards, barry
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 36487893
Or you could use OFFSET to create the range to be averaged.

=AVERAGE(OFFSET(Ref,RowOffset,ColOffset,Height,Width))

Ref - first column of particular row
Rowoffset - Current row so 0
Coloffset - use Match to find column with date and less 3 for 4 weeks earlier.
Height - only one row so 1
Width - 4 weeks so 4

Thanks
Rob H
0
 

Author Comment

by:JAK11
ID: 36495409
This is great thanks.

If there are no data in the week columns how do i tell it to average the weeks with the data in. For eg if 11/07/11 didn't contain data i would want to take the 4 weeks average from the cells which do contain the data so this would take average 4 prev average from 04/07/11.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question