Given this spreadsheet image, I want to calculate and display a value based on a 5 day moving average (last 5 days). I want this to be an automatic function, something that doesn’t require daily manual adjustments ot the formula. I can’t figure out how to do this, so can anyone offer a suggestion?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
How to? (Office 2002 SP3)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » How to? (Office 2002 SP3)
- This topic has 35 replies, 7 voices, and was last updated 20 years, 3 months ago.
Viewing 4 reply threadsAuthorReplies-
WSsdckapr
AskWoody Lounger -
ibe98765
AskWoody PlusDecember 7, 2004 at 9:18 am #909934No, that doesn’t work. I think the problem might be with the B2:B23 part. The average function can’t handle data that isn’t filled in.
My example wasn’t meant to be absolute. This speadsheet will grow. Right now, there is about 200 rows of data and most of them are empty right now. But I only need the last 5 entries for this formula (in this case, B19:B23). Yesterday, it would have been B18:B22. The day before, B17:B21. Does this make sense?
-
WSEowyn
AskWoody Lounger -
WSsdckapr
AskWoody LoungerDecember 7, 2004 at 10:09 am #909954Using a dynamic range is an excellent technique. My only concern would be determining the last 5 in the list, versus the requested last 5 in time:
The dynamic range technique grows the range as the list is expanded.
The dates seem to be filled in ahead of time so they can not be used to determine the end and the col B values might have internal blanks, making countA ineffective for determining the size of the data.
Steve
-
WSsdckapr
AskWoody LoungerDecember 7, 2004 at 10:09 am #909955Using a dynamic range is an excellent technique. My only concern would be determining the last 5 in the list, versus the requested last 5 in time:
The dynamic range technique grows the range as the list is expanded.
The dates seem to be filled in ahead of time so they can not be used to determine the end and the col B values might have internal blanks, making countA ineffective for determining the size of the data.
Steve
-
-
WSEowyn
AskWoody Lounger -
WSsdckapr
AskWoody LoungerDecember 7, 2004 at 10:01 am #909950The only blanks that would affect this are the blanks that are in the “last 5 days” and they would be summed as zero. Try this – it will ignore the blanks in the cells that are in the range:
=AVERAGE(IF(ISNUMBER(B2:B23)*(A2:A23>(TODAY()-5))*(A2:A23(TODAY()-5))*(A2:A300<=TODAY()),B2:B300))
Steve
-
ibe98765
AskWoody Plus -
WSsdckapr
AskWoody LoungerDecember 7, 2004 at 1:03 pm #910026If you put in G25 the array formula (confirm with cntrl-shift-enter):
=AVERAGE(IF(ISNUMBER(G2:G23)*(F2:F23>(TODAY()-5))*(F2:F23(TODAY()-5))*(A2:A23(TODAY()-5))*(F2:F23<=TODAY()),G2:G23))}
[Note the squiggly brackets ({}) that excel adds (you do not add them) to indicate an array formula]If they are not there, press edit (while still in cell G25) then hold both and buttons while pressing the key.
Steve
-
ibe98765
AskWoody Plus -
WSHansV
AskWoody LoungerDecember 7, 2004 at 10:26 pm #910326Confirming a formula with Ctrl+Shift+Enter makes the formula into an array formula. The curly brackets { } are Excel’s way to give the user a visual clue that the formula is an array formula, not a standard formula.
What is an array formula? Here is a very simple example:
A B 1 6 3 2 4 1 3 2 2 If you enter the formula =SUM(A1:A3/B1:B3) in another cell as a normal formula, the result will be #VALUE. In a normal value, dividing one range of cells by another range of cells doesn’t make sense. But if you enter it as an array formula, Excel will evaluate the division cell by cell, i.e. it calculates A1/B1, A2/B2 and A3/B3, and then calculate the SUM. The result is 6/3 + 4/1 + 2/2 = 2 + 4 + 1 = 7.
If you search this forum for array formula, you will find many examples, and links to other sites providing explanations and examples.
-
WSHansV
AskWoody LoungerDecember 7, 2004 at 10:26 pm #910327Confirming a formula with Ctrl+Shift+Enter makes the formula into an array formula. The curly brackets { } are Excel’s way to give the user a visual clue that the formula is an array formula, not a standard formula.
What is an array formula? Here is a very simple example:
A B 1 6 3 2 4 1 3 2 2 If you enter the formula =SUM(A1:A3/B1:B3) in another cell as a normal formula, the result will be #VALUE. In a normal value, dividing one range of cells by another range of cells doesn’t make sense. But if you enter it as an array formula, Excel will evaluate the division cell by cell, i.e. it calculates A1/B1, A2/B2 and A3/B3, and then calculate the SUM. The result is 6/3 + 4/1 + 2/2 = 2 + 4 + 1 = 7.
If you search this forum for array formula, you will find many examples, and links to other sites providing explanations and examples.
-
ibe98765
AskWoody PlusJanuary 9, 2005 at 7:43 am #919794Looks like something I’m doing isn’t working…
Have this data representing sleep times:
Col A……………………….Col D
Wed 29-Dec-2004….6:25
Thu 30-Dec-2004…..7:38
Fri 31-Dec-2004…….7:20
Sat 1-Jan-2005……..7:52
Sun 2-Jan-2005…….7:20
Mon 3-Jan-2005…….6:30
Tue 4-Jan-2005…….7:40
Wed 5-Jan-2005……5:35
Sat 0-Jan-1900……..7:00
Fri 7-Jan-2005………6:20
Sat 8-Jan-2005……..7:20Using this formula:
{=AVERAGE(IF(ISNUMBER(D4:D220)*(A4:A220>((TODAY()-1)-5))*(A4:A220<=(TODAY()-1)),D4:D220))}I get the following averages:
Last 5 days………….6:31
Last 10 days………..6:57note: (The last data element isn't used until the following day as it caused problems if there was no data filled into the space).
BUT when I select the data manually and look at the built-in average function in the status bar at the bottom of the sheet, the numbers don't match.
Instead I see:
Last 5 days………….6:37
Last 10 days………..6:58Anyone have any ideas why my calculated averages don't match Excel's?
Thanks!
-
WSsdckapr
AskWoody LoungerJanuary 9, 2005 at 9:48 am #919816 -
ibe98765
AskWoody Plus -
ibe98765
AskWoody Plus -
WSHansV
AskWoody LoungerJanuary 20, 2005 at 7:17 am #923279Excel is not clairvoyant – it just looks at the two times and it has no idea that one of them might be on the next day, unless you specify that yourself. Try
=(IF(B51=0;””;C51-B51+(C51<B51))
If the time in C51 is earlier than that in B51, that in C51 is on the next day, so we have to add one day. The formula uses the fact that TRUE=1 and FALSE=0 to do this.
-
WSsdckapr
AskWoody LoungerJanuary 20, 2005 at 11:43 am #923348Of course this assumes that the day is only 1 day later
ibe98765,
In many instances, I have found, that it is best to not separate date and time. Excel easily lets you put both together in a cell and format it to display both (eg) “mmm d, yyyy h:mm AM/PM” as a format will display something like:”Jan 20, 2005 7:45 AM”Then when you do the math, it won’t matter if it is the same day, or multiple days later.
Steve
-
WSHansV
AskWoody LoungerJanuary 20, 2005 at 12:01 pm #923352> Of course this assumes that the day is only 1 day later
Certainly. Since the OP only records the time, that seemed a reasonable assumption. If the second time could be more than one day after the first time, there is no way to tell how many.
I agree that not separating the day and time is MUCH better.
-
ibe98765
AskWoody PlusJanuary 23, 2005 at 7:06 am #924064This worked for me because the times computed are for sleep time, so they will never be farther apart than 1 day. Strangely, the one instance where this formula didn’t work (so far) was when the first time (column
was exactly 12:00AM.
I’ve never thought of keeping the date and times together. Will such a format still allow an average to be computed? Remeber, I am using the array formula from above.
-
WSsdckapr
AskWoody LoungerJanuary 23, 2005 at 9:38 am #924069Yes, calculations will still work. Most times using date/times will simplify calculations since you can subtract them directly to gt time difference
Date/TIme are stored as numbers in excel. They are in units of days. The “integer part” of the date/time is the “date portion”. It is the number of days past Jan 1, 1900. The “decimal part” is the fraction of the day that is past (eg): 0 = Midnight, 0.25 = 6AM, 0.5 = Noon, 0.75 = 6PM, 1= Midnight of next day.
Any date/time subtraction gives the number of DAYS elapsed. You can format this using format cells to give hrs/min/secs in a variety of formats (though it still retains the units of days), or you can manipulate yourself by multiplying by factors. Multiply the days by 24 to give hours, 24*60 to give mins, etc
Steve
-
ibe98765
AskWoody Plus -
WSsdckapr
AskWoody LoungerJanuary 9, 2005 at 9:48 am #919817 -
ibe98765
AskWoody PlusJanuary 9, 2005 at 7:43 am #919795Looks like something I’m doing isn’t working…
Have this data representing sleep times:
Col A……………………….Col D
Wed 29-Dec-2004….6:25
Thu 30-Dec-2004…..7:38
Fri 31-Dec-2004…….7:20
Sat 1-Jan-2005……..7:52
Sun 2-Jan-2005…….7:20
Mon 3-Jan-2005…….6:30
Tue 4-Jan-2005…….7:40
Wed 5-Jan-2005……5:35
Sat 0-Jan-1900……..7:00
Fri 7-Jan-2005………6:20
Sat 8-Jan-2005……..7:20Using this formula:
{=AVERAGE(IF(ISNUMBER(D4:D220)*(A4:A220>((TODAY()-1)-5))*(A4:A220<=(TODAY()-1)),D4:D220))}I get the following averages:
Last 5 days………….6:31
Last 10 days………..6:57note: (The last data element isn't used until the following day as it caused problems if there was no data filled into the space).
BUT when I select the data manually and look at the built-in average function in the status bar at the bottom of the sheet, the numbers don't match.
Instead I see:
Last 5 days………….6:37
Last 10 days………..6:58Anyone have any ideas why my calculated averages don't match Excel's?
Thanks!
-
ibe98765
AskWoody Plus -
WSsdckapr
AskWoody LoungerDecember 7, 2004 at 1:03 pm #910027If you put in G25 the array formula (confirm with cntrl-shift-enter):
=AVERAGE(IF(ISNUMBER(G2:G23)*(F2:F23>(TODAY()-5))*(F2:F23(TODAY()-5))*(A2:A23(TODAY()-5))*(F2:F23<=TODAY()),G2:G23))}
[Note the squiggly brackets ({}) that excel adds (you do not add them) to indicate an array formula]If they are not there, press edit (while still in cell G25) then hold both and buttons while pressing the key.
Steve
-
-
ibe98765
AskWoody Plus
-
-
WSsdckapr
AskWoody LoungerDecember 7, 2004 at 10:01 am #909951The only blanks that would affect this are the blanks that are in the “last 5 days” and they would be summed as zero. Try this – it will ignore the blanks in the cells that are in the range:
=AVERAGE(IF(ISNUMBER(B2:B23)*(A2:A23>(TODAY()-5))*(A2:A23(TODAY()-5))*(A2:A300<=TODAY()),B2:B300))
Steve
-
-
ibe98765
AskWoody PlusDecember 7, 2004 at 9:18 am #909935No, that doesn’t work. I think the problem might be with the B2:B23 part. The average function can’t handle data that isn’t filled in.
My example wasn’t meant to be absolute. This speadsheet will grow. Right now, there is about 200 rows of data and most of them are empty right now. But I only need the last 5 entries for this formula (in this case, B19:B23). Yesterday, it would have been B18:B22. The day before, B17:B21. Does this make sense?
-
-
WSsdckapr
AskWoody Lounger -
WSchipshot
AskWoody LoungerDecember 7, 2004 at 8:10 pm #910284If your list starts in B2 and there are no embedded blank entries, you can try:
=average(offset(B2,count(B2:B100)-1,0,-min(5,count(B2:B100)),1))
If there are embedded blank entries, then you need to tell us how those should be considered in your average. Do you still want the last 5 days (even if there may be fewer than 5 data points), or do you want the last 5 observed data points?
-
WSchipshot
AskWoody LoungerDecember 7, 2004 at 8:10 pm #910285If your list starts in B2 and there are no embedded blank entries, you can try:
=average(offset(B2,count(B2:B100)-1,0,-min(5,count(B2:B100)),1))
If there are embedded blank entries, then you need to tell us how those should be considered in your average. Do you still want the last 5 days (even if there may be fewer than 5 data points), or do you want the last 5 observed data points?
-
WSAladin Akyurek
AskWoody LoungerJanuary 23, 2005 at 10:39 am #924073If you insist on having the average of the last 5 values in column B in the same column, say, in B25 as your exhibit shows:
=AVERAGE(OFFSET($B$2,MATCH(9.99999999999999E+307,$B$2:OFFSET(INDEX(B:B,ROW()-1),0,0))-5,0,5))
You can enter this formula in a cell just below the last record indexed by the last date.
If you’re willing to calculate the average of the last 5 values in column B outside A:B, say, in C2…
=AVERAGE(INDEX($B$2:$B$65536,MATCH(9.99999999999999E+307,$B$2:$B$65536)-4):INDEX($B$2:$B$65536,MATCH(9.99999999999999E+307,$B$2:$B$65536)))
If so desired, the MATCH bit can be entered in C1… Thus:
C1:
=MATCH(9.99999999999999E+307,$B$2:$B$65536)
C2 becomes then:
=AVERAGE(INDEX($B$2:$B$65536,C1-4):INDEX($B$2:$B$65536,C1))
-
WSunkamunka
AskWoody LoungerJanuary 25, 2005 at 8:45 pm #924714Just out of curiosity. You frequently use 9.99999999999999E+307 in your formulas. Do you have code that delivers that to the appropriate cursor point – or is there an Excel “function” (or shortcut thereto) that generates the characters? Or maybe you do it by hand every time, after all.
-
WSAladin Akyurek
AskWoody Lounger
-
-
Viewing 4 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Outdated Laptop
by
jdamkeene
1 hour, 43 minutes ago -
Updating Keepass2Android
by
CBFPD-Chief115
1 hour, 56 minutes ago -
Another big Microsoft layoff
by
Charlie
1 hour, 36 minutes ago -
PowerShell to detect NPU – Testers Needed
by
RetiredGeek
1 hour, 25 minutes ago -
May 2025 updates are out
by
Susan Bradley
2 hours, 1 minute ago -
Windows 11 Insider Preview build 26200.5600 released to DEV
by
joep517
7 hours, 40 minutes ago -
Windows 11 Insider Preview build 26120.3964 (24H2) released to BETA
by
joep517
7 hours, 42 minutes ago -
Drivers suggested via Windows Update
by
Tex265
7 hours, 33 minutes ago -
Thunderbird release notes for 128 esr have disappeared
by
EricB
5 hours, 17 minutes ago -
CISA mutes own website, shifts routine cyber alerts to X, RSS, email
by
Nibbled To Death By Ducks
14 hours, 32 minutes ago -
Apple releases 18.5
by
Susan Bradley
8 hours, 57 minutes ago -
Fedora Linux 40 will go end of life for updates and support on 2025-05-13.
by
Alex5723
15 hours, 58 minutes ago -
How a new type of AI is helping police skirt facial recognition bans
by
Alex5723
16 hours, 36 minutes ago -
Windows 7 ISO /Windows 10 ISO
by
ECWS
1 hour, 26 minutes ago -
No HP software folders
by
fpefpe
1 day ago -
Which antivirus apps and VPNs are the most secure in 2025?
by
B. Livingston
3 hours, 41 minutes ago -
Stay connected anywhere
by
Peter Deegan
1 day, 5 hours ago -
Copilot, under the table
by
Will Fastie
20 hours, 53 minutes ago -
The Windows experience
by
Will Fastie
1 day, 11 hours ago -
A tale of two operating systems
by
Susan Bradley
1 day, 2 hours ago -
Microsoft : Resolving Blue Screen errors in Windows
by
Alex5723
1 day, 17 hours ago -
Where’s the cache today?
by
Up2you2
2 days, 8 hours ago -
Ascension says recent data breach affects over 430,000 patients
by
Nibbled To Death By Ducks
2 days, 1 hour ago -
Nintendo Switch 2 has a remote killing switch
by
Alex5723
1 day, 1 hour ago -
Blocking Search (on task bar) from going to web
by
HenryW
3 hours, 54 minutes ago -
Windows 10: Microsoft 365 Apps will be supported up to Oct. 10 2028
by
Alex5723
3 days, 1 hour ago -
Add or Remove “Ask Copilot” Context Menu in Windows 11 and 10
by
Alex5723
3 days, 1 hour ago -
regarding april update and may update
by
heybengbeng
3 days, 3 hours ago -
MS Passkey
by
pmruzicka
2 days, 5 hours ago -
Can’t make Opera my default browser
by
bmeacham
3 days, 11 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.