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, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
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 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
-
Updates seem to have broken Microsoft Edge
by
rebop2020
3 hours, 34 minutes ago -
Wait command?
by
CWBillow
15 minutes ago -
Malwarebytes 5 Free version manual platform updates
by
Bob99
6 hours, 29 minutes ago -
inetpub : Microsoft’s patch for CVE-2025–21204 introduces vulnerability
by
Alex5723
13 hours, 4 minutes ago -
Windows 10 finally gets fix
by
Susan Bradley
21 hours, 58 minutes ago -
AMD Ryzen™ Chipset Driver Release Notes 7.04.09.545
by
Alex5723
23 hours, 18 minutes ago -
Win 7 MS Essentials suddenly not showing number of items scanned.
by
Oldtimer
17 hours, 51 minutes ago -
France : A law requiring messaging apps to implement a backdoor ..
by
Alex5723
1 day, 12 hours ago -
Dev runs Windows 11 ARM on an iPad Air M2
by
Alex5723
1 day, 13 hours ago -
MS-DEFCON 3: Cleanup time
by
Susan Bradley
8 hours, 11 minutes ago -
KB5056686 (.NET v8.0.15) Delivered Twice in April 2025
by
lmacri
4 hours, 52 minutes ago -
How to enable Extended Security Maintenance on Ubuntu 20.04 LTS before it dies
by
Alex5723
2 days ago -
Windows 11 Insider Preview build 26200.5562 released to DEV
by
joep517
2 days, 4 hours ago -
Windows 11 Insider Preview build 26120.3872 (24H2) released to BETA
by
joep517
2 days, 4 hours ago -
Unable to eject external hard drives
by
Robertos42
14 hours, 55 minutes ago -
Saying goodbye to not-so-great technology
by
Susan Bradley
2 hours, 36 minutes ago -
Tech I don’t miss, and some I do
by
Will Fastie
30 minutes ago -
Synology limits hard drives
by
Susan Bradley
3 days, 8 hours ago -
Links from Microsoft 365 and from WhatsApp not working
by
rog7
2 days, 11 hours ago -
WhatsApp Security Advisories CVE-2025-30401
by
Alex5723
3 days, 14 hours ago -
Upgrade Sequence
by
doneager
3 days, 8 hours ago -
Chrome extensions with 6 million installs have hidden tracking code
by
Nibbled To Death By Ducks
1 day, 13 hours ago -
Uninstall “New Outlook” before installing 2024 Home & Business?
by
Tex265
2 days, 6 hours ago -
The incredible shrinking desktop icons
by
Thumper
4 days, 11 hours ago -
Windows 11 Insider Preview Build 22635.5240 (23H2) released to BETA
by
joep517
4 days, 13 hours ago -
Connecting hard drive on USB 3.2 freezes File Explorer & Disk Management
by
WSJMGatehouse
1 day, 12 hours ago -
Shellbag Analyser & Cleaner Update
by
Microfix
1 day, 5 hours ago -
CISA warns of increased breach risks following Oracle Cloud leak
by
Nibbled To Death By Ducks
4 days, 22 hours ago -
Outlook 2024 two sent from email addresses
by
Kathy Stevens
8 hours, 18 minutes ago -
Speeding up 11’s search
by
Susan Bradley
2 days, 10 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.