Average of last 5 nonblank values in row with matching date

MatthewChung

New Member
Joined
Nov 18, 2021
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone!

After spending days and days trying to figure out this problem without any success, I decided to seek further assistance by posting it here. I understand there are some very similar posts which I have been through but it got out of hand very quickly...

I am working in a table with daily productivity rates and would like to determine the average of the last 5 working days (excluding blanks) based on a moving date. The formula below was what I started with but it included blanks as well which returned an average of 54 when I wanted it to return an average of 60.

=AVERAGE(OFFSET(E9,0,MATCH(B2,F6:AI6,0),1,-5))

As soon as I added additional criteria in the formula below, it returned strange values and became way to difficult for me to understand.

=AVERAGE(OFFSET(E9,0,MATCH(B2,F6:AI6,0),1,SMALL(IF(ISNUMBER(F9:AI9),ROW(F9:AI9)),MIN(5,COUNT(F9:AI9)))))

Any help would be very much appreciated. Thank you!
 

Attachments

  • Average Offset Formula.JPG
    Average Offset Formula.JPG
    141.2 KB · Views: 23
This works with weekends included

Average of last 5 nonblank values in row with matching date_Matthew Chung.xlsx
CDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAI
619/11/20211-Nov-212-Nov-213-Nov-214-Nov-215-Nov-216-Nov-217-Nov-218-Nov-219-Nov-2110-Nov-2111-Nov-2112-Nov-2113-Nov-2114-Nov-2115-Nov-2116-Nov-2117-Nov-2118-Nov-2119-Nov-2120-Nov-2121-Nov-2122-Nov-2123-Nov-2124-Nov-2125-Nov-2126-Nov-2127-Nov-2128-Nov-2129-Nov-2130-Nov-21
7
8
9productivity711486531438521938461916131317164343205656
10
11Yesterday18/11/2021
125 days Prior12/11/2021
13Last Week
1460
Sheet1
Cell Formulas
RangeFormula
C6C6=TODAY()
D11D11=TODAY()-1
D12D12=WORKDAY(D11,-4)
C14C14=AVERAGEIFS($F$9:$AI$9,$F$6:$AI$6,">="&$D$12,$F$6:$AI$6,"<="&$D$11,$F$9:$AI$9,"<>""")

Correct version here sorry! With the WORKDAY function you put in, the formula averages the workdays including the Saturday productivity which is across 6 days and not 5.
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
if we force the previous 5th day 13 - 18th the average for positive cells is 54?

We only returned 60 when we included the 12th - across 6 days - is this ok?
 
Upvote 0
Back to 7 days, 5-working days are included, no more, no less.
Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAI
1
2
3
4
5MonTueWedThuFriSatSunMonTueWedThuFriSatSunMonTueWedThuFriSatSunMonTueWedThuFriSatSunMonTue
601/11/202102/11/202103/11/202104/11/202105/11/202106/11/202107/11/202108/11/202109/11/202110/11/202111/11/202112/11/202113/11/202114/11/202115/11/202116/11/202117/11/202118/11/202119/11/202120/11/202121/11/202122/11/202123/11/202124/11/202125/11/202126/11/202127/11/202128/11/202129/11/202130/11/2021
7
8
9productivity71148653143852193841619161313917164343205656
10
11
12
13
14
15last work week60
Sheet1
Cell Formulas
RangeFormula
F5:AI5F5=TEXT(F6,"ddd")
D15D15=AVERAGEIFS($F9:$AI9,$F$6:$AI$6,"<"&TODAY(),$F$6:$AI$6,">="&TODAY()-7,$F$5:$AI$5,"<>s*")


Above ir not take holidays into account. Tell me for update solution if holidays are counted.
 
Upvote 0
Argh my values were against the wrong dates

=AVERAGEIFS($F$9:$AI$9,$F$6:$AI$6,">="&$C$6-5,$F$6:$AI$6,"<="&$C$6,$F$9:$AI$9,"<>""") = 60

13th 84
15th 61
16th 91
17th 61
18th 3

B2 -1 would've been the 17th.
 
Upvote 0
if we force the previous 5th day 13 - 18th the average for positive cells is 54?

We only returned 60 when we included the 12th - across 6 days - is this ok?
30-Nov-21
montuewedthufrisatsunmontuewedthufrisatsunmontuewedthufrisatsunmontuewedthufrisatsunmontue
1-Nov-212-Nov-213-Nov-214-Nov-215-Nov-216-Nov-217-Nov-218-Nov-219-Nov-2110-Nov-2111-Nov-2112-Nov-2113-Nov-2114-Nov-2115-Nov-2116-Nov-2117-Nov-2118-Nov-2119-Nov-2120-Nov-2121-Nov-2122-Nov-2123-Nov-2124-Nov-2125-Nov-2126-Nov-2127-Nov-2128-Nov-2129-Nov-2130-Nov-21
productivity711486531438521938415619161313917164343205656
last work week40.5


Hi RasGhul

Thank you for your response once again. I have entered some data in Saturdays, Sundays in separate weeks and left both of them some weeks completely blank. In this scenario the average of the previous 5 cells should return a value of 35.6 but the formula says 40.5.
 
Upvote 0
@RasGhul, blank cell does not effect to average. I believe he does not want to do average for Sat/Sun if there was productivity in weekend.
 
Upvote 0
@RasGhul, blank cell does not effect to average. I believe he does not want to do average for Sat/Sun if there was productivity in weekend.
Hi bebo

The averages need to be taken if there is data in the previous 5 cells (weekends included if there is productivity).
 
Upvote 0
Did you adjust the end date in the formula? or B2 should be TODAY()-1(18/11/21)

=AVERAGEIFS($F$9:$AI$9,$F$6:$AI$6,">="&$C$6-5,$F$6:$AI$6,"<="&today()-1,$F$9:$AI$9,"<>""")
 
Upvote 0
Did you adjust the end date in the formula? or B2 should be TODAY()-1(18/11/21)

=AVERAGEIFS($F$9:$AI$9,$F$6:$AI$6,">="&$C$6-5,$F$6:$AI$6,"<="&today()-1,$F$9:$AI$9,"<>""")
Sorry, I did not copy the correct data.

Book1.xlsx
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAI
230-Nov-21
3
4
5montuewedthufrisatsunmontuewedthufrisatsunmontuewedthufrisatsunmontuewedthufrisatsunmontue
61-Nov-212-Nov-213-Nov-214-Nov-215-Nov-216-Nov-217-Nov-218-Nov-219-Nov-2110-Nov-2111-Nov-2112-Nov-2113-Nov-2114-Nov-2115-Nov-2116-Nov-2117-Nov-2118-Nov-2119-Nov-2120-Nov-2121-Nov-2122-Nov-2123-Nov-2124-Nov-2125-Nov-2126-Nov-2127-Nov-2128-Nov-2129-Nov-2130-Nov-21
7
8
9productivity711486531438521938415619161313917164343205656
10
11
12
13
14
15last work week40.5
Sheet1
Cell Formulas
RangeFormula
D15D15=AVERAGEIFS($F$9:$AI$9,$F$6:$AI$6,">="&WORKDAY(B2,-4),$F$6:$AI$6,"<="&B2-1,$F$9:$AI$9,"<>""")


I substituted TODAY() with a cell reference so the date can be manually adjusted.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top