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, 2 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 LoungerWSchipshot
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
-
Defunct domain for Microsoft account
by
CWBillow
4 hours, 16 minutes ago -
24H2??
by
CWBillow
50 minutes ago -
W11 23H2 April Updates threw ‘class not registered’
by
WindowsPersister
1 hour, 34 minutes ago -
Master patch listing for April 8th, 2025
by
Susan Bradley
7 hours, 48 minutes ago -
TotalAV safety warning popup
by
Theodore Nicholson
1 hour, 14 minutes ago -
two pages side by side land scape
by
marc
1 day, 14 hours ago -
Deleting obsolete OneNote notebooks
by
afillat
1 day, 16 hours ago -
Word/Outlook 2024 vs Dragon Professional 16
by
Kathy Stevens
19 hours, 35 minutes ago -
Security Essentials or Defender?
by
MalcolmP
22 hours, 20 minutes ago -
April 2025 updates out
by
Susan Bradley
4 hours, 54 minutes ago -
Framework to stop selling some PCs in the US due to new tariffs
by
Alex5723
15 hours, 41 minutes ago -
WARNING about Nvidia driver version 572.83 and 4000/5000 series cards
by
Bob99
5 hours, 46 minutes ago -
Creating an Index in Word 365
by
CWBillow
1 day, 8 hours ago -
Coming at Word 365 and Table of Contents
by
CWBillow
23 hours, 46 minutes ago -
Windows 11 Insider Preview Build 22635.5170 (23H2) released to BETA
by
joep517
2 days, 11 hours ago -
Has the Microsoft Account Sharing Problem Been Fixed?
by
jknauth
2 days, 15 hours ago -
W11 24H2 – Susan Bradley
by
G Pickerell
2 days, 17 hours ago -
7 tips to get the most out of Windows 11
by
Alex5723
2 days, 15 hours ago -
Using Office apps with non-Microsoft cloud services
by
Peter Deegan
2 days, 8 hours ago -
I installed Windows 11 24H2
by
Will Fastie
14 hours, 37 minutes ago -
NotifyIcons — Put that System tray to work!
by
Deanna McElveen
2 days, 20 hours ago -
Decisions to be made before moving to Windows 11
by
Susan Bradley
1 hour, 48 minutes ago -
Port of Seattle says ransomware breach impacts 90,000 people
by
Nibbled To Death By Ducks
3 days, 4 hours ago -
Looking for personal finance software with budgeting capabilities
by
cellsee6
2 days, 12 hours ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
2 days, 13 hours ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
3 days, 21 hours ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
4 days, 6 hours ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
5 hours, 46 minutes ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
3 days, 14 hours ago -
Is data that is in OneDrive also taking up space on my computer?
by
WShollis1818
4 days, 1 hour 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.