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
-
Ubuntu 25.04 (Plucky Puffin)
by
Alex5723
1 hour, 55 minutes ago -
24H2 fixed??
by
CWBillow
1 hour, 37 minutes ago -
Uninstalr Updates
by
jv16
4 hours, 4 minutes ago -
Apple zero days for April
by
Susan Bradley
9 hours, 29 minutes ago -
CVE program gets last-minute funding from CISA – and maybe a new home
by
Nibbled To Death By Ducks
14 hours, 59 minutes ago -
Whistleblower describes DOGE IT dept rumpus at America’s labor watchdog
by
Nibbled To Death By Ducks
1 day, 2 hours ago -
Seeing BSOD’s on 24H2?
by
Susan Bradley
9 hours, 43 minutes ago -
TUT For Private Llama LLM, Local Installation and Isolated from the Internet.
by
bbearren
17 hours, 12 minutes ago -
Upgrade from Windows 10 to 11
by
Holdsworth8
1 day, 11 hours ago -
Microsoft : AI-powered deception: Emerging fraud threats and countermeasures
by
Alex5723
1 day, 14 hours ago -
0patch
by
WSjcgc50
15 hours, 17 minutes ago -
Devices might encounter blue screen exception with the recent Windows updates
by
Susan Bradley
1 day, 7 hours ago -
Windows 11 Insider Preview Build 22631.5261 (23H2) released to Release Preview
by
joep517
1 day, 17 hours ago -
Problem opening image attachments
by
RobertG
1 day, 18 hours ago -
advice for setting up a new windows computer
by
routtco1001
2 days, 9 hours ago -
It’s Identity Theft Day!
by
Susan Bradley
1 day, 13 hours ago -
Android 15 require minimum 32GB of storage
by
Alex5723
2 days, 14 hours ago -
Mac Mini 2018, iPhone 6s 2015 Are Now Vintage
by
Alex5723
2 days, 14 hours ago -
Hertz says hackers stole customer credit card and driver’s license data
by
Alex5723
2 days, 15 hours ago -
Firefox became sluggish
by
Rick Corbett
7 hours, 25 minutes ago -
Windows 10 Build 19045.5794 (22H2) to Release Preview Channel
by
joep517
2 days, 19 hours ago -
Windows 11 Insider Preview Build 22635.5235 (23H2) released to BETA
by
joep517
2 days, 19 hours ago -
A Funny Thing Happened on the Way to the Forum
by
bbearren
1 day, 16 hours ago -
Download speeds only 0.3Mbps after 24H2 upgrade on WiFi and Ethernet
by
John
3 minutes ago -
T-Mobile 5G Wireless Internet
by
WSmmi16
1 day, 17 hours ago -
Clock missing above calendar in Windows 10
by
WSCape Sand
1 day, 18 hours ago -
Formula to Calculate Q1, Q2, Q3, or Q4 of the Year?
by
WSJon5
3 days, 10 hours ago -
The time has come for AI-generated art
by
Catherine Barrett
2 days, 14 hours ago -
Hackers are using two-factor authentication to infect you
by
B. Livingston
3 days ago -
23 and you
by
Max Stul Oppenheimer
3 days, 7 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.