Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 829
Default How to Calculate the average Daily price within a time period

"Alfred Heiligenbrunner" wrote:
In C1 put this formula:
=IF(OR(A2<$G$1,A1$G$2),0,MIN(A2,$G$2)-MAX(A1,$G$1))*B1
and fill it down. Your average is
=SUM(C:C)/($G$2-$G$1)


Thanks for that! I have been struggling for 3 days to find a relatively
simple formula. Your design provided the structure that had eluded me.

We can do this without a helper column. Alternatively, array-enter the
following formula (press ctrl+shift+Enter instead of just Enter):

=SUM(IF(G1<=$A$2:$A$10,IF($A$1:$A$9<=G2+1,$B$1:$B$ 9
*(IF(G2+1<$A$2:$A$10,G2+1,$A$2:$A$10)-IF(G1=$A$1:$A$9,G1,$A$1:$A$9)))))
/ (G2+1-G1)

That assumes the table of dates and prices is in A1:B10, with 31 Dec 9999
(max possible date) in A10. B10 can be empty.

And it assumes the start date is in G1, the end date is in G2, and we want
to calculate the daily average over that period inclusive of those dates
(i.e. G2+1-G1).

The formula works correctly only if G1 is not before the first date in A1.
Otherwise, the formula returns bogus results. Of course, we could add a
sanity check by array-entering the following formula (press ctrl+shift+Enter
instead of just Enter):

=IF(G1<$A$1,NA(),SUM(...)/(G2+1G1))

-----
Not recommended.... If you want to avoid an array-enter formula, you can
normally-enter the following formula (press Enter as usual):

=IF(G1<$A$1,NA(),SUMPRODUCT((G1<=A2:A10)*(A1:A9<=G 2+1),B1:B9,
(G2+1<A2:A10)*(G2+1)+(G2+1=A2:A10)*A2:A10-(G1=A1:A9)*G1-(G1<A1:A9)*A1:A9)
/ (G2+1-G1))

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 829
Default How to Calculate the average Daily price within a time period

Errata....
"joeu2004" wrote:
=IF(G1<$A$1,NA(),SUMPRODUCT((G1<=A2:A10)*(A1:A9<=G 2+1),B1:B9,
(G2+1<A2:A10)*(G2+1)+(G2+1=A2:A10)*A2:A10-(G1=A1:A9)*G1-(G1<A1:A9)*A1:A9)
/ (G2+1-G1))


I forgot to add the appropriate absolute references, to wit:

=IF(G1<$A$1,NA(),SUMPRODUCT((G1<=$A$2:$A$10)*($A$1 :$A$9<=G2+1),$B$1:$B$9,
(G2+1<$A$2:$A$10)*(G2+1)+(G2+1=$A$2:$A$10)*$A$2:$ A$10
-(G1=$A$1:$A$9)*G1-(G1<$A$1:$A$9)*$A$1:$A$9)
/ (G2+1-G1))

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4
Default How to Calculate the average Daily price within a time period

joeu2004 schrieb am 04.03.2015 12:30:47 mit Betreff " How to
Calculate the average Daily price within a time period":
Errata....
"joeu2004" wrote:
=IF(G1<$A$1,NA(),SUMPRODUCT((G1<=A2:A10)*(A1:A9<=G 2+1),B1:B9,
(G2+1<A2:A10)*(G2+1)+(G2+1=A2:A10)*A2:A10-(G1=A1:A9)*G1-(G1<A1:A9)*A1:A9)

/ (G2+1-G1))


I forgot to add the appropriate absolute references, to wit:

=IF(G1<$A$1,NA(),SUMPRODUCT((G1<=$A$2:$A$10)*($A$1 :$A$9<=G2+1),$B$1:$B$9,
(G2+1<$A$2:$A$10)*(G2+1)+(G2+1=$A$2:$A$10)*$A$2:$ A$10
-(G1=$A$1:$A$9)*G1-(G1<$A$1:$A$9)*$A$1:$A$9)
/ (G2+1-G1))


Great.
Thanks for sharing.
Alfred
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to average values based on time period Peters48 Excel Worksheet Functions 6 January 9th 10 06:36 PM
Calculate Average for same period last year irish_hp Excel Discussion (Misc queries) 3 April 16th 08 11:22 AM
average rate of change per given time period between 2 moments in time of a value David Virgil Hobbs Excel Worksheet Functions 1 December 19th 06 07:24 AM
average rate of change per given time period between 2 moments in time of a value David Virgil Hobbs Excel Programming 1 December 19th 06 07:24 AM
calculate/convert volume price to monthly average price Bultgren Excel Worksheet Functions 2 February 14th 06 09:36 AM


All times are GMT +1. The time now is 05:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"