Countif Until

aoifew

New Member
Joined
Jun 23, 2019
Messages
18
Hi
I’d like to average hours worked every 5 days but need toexclude days where no hours have been worked. Was playing about with AverageIf to achieve this and wouldn’t be aproblem for the formula in cell below (answer is 9.6). However, if I drag the formula along (Formula 2), the average will onlybe for 4 days as it’ll ignore the zero in the cell for Day 6. Is there a way of dynamically referencing theprevious 5 cells where hours have been worked?

Thanks

Day 1
Day 2
Day 3
Day 4
Day 5
Day 6
Day 7
Day 8
Day 9
Day 10
8
8
8
12
12
0
0
8
8
8
9.6
Formula 2
Formula 3
Formula 4
Formula 5
Formula 6


<tbody>
</tbody>
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
In your example, does the 2nd result average day2 through day6 but not consider the 0 in day6? So, the result would be 10?
 
Last edited:
Upvote 0
Is this what you want:


Book1
ABCDEFGHIJ
1Day 1Day 2Day 3Day 4Day 5Day 6Day 7Day 8Day 9Day 10
2888121200888
3Average->9.61010.6666710.666679.3333338
Sheet8
Cell Formulas
RangeFormula
E3=AVERAGEIF(A2:E2,">0")
 
Upvote 0
Hi
Thanks for the responses and apologies for my less than clear explanation.

In the example given, as the hours worked on Day 6 was zero, I'd like the formula in F3 to ignore zeroes and simply reflect the last 5 days worked. i.e. 9.6. Same will apply to G3 but on Day 8 the answer should be the average of Days 8,5,4,3,and 2 (previous 5 days that "<> 0") which coincidentally in my poor example is also 9.6
 
Upvote 0
Is this what you are looking for:


Book1
ABCDEFGHIJ
1Day 1Day 2Day 3Day 4Day 5Day 6Day 7Day 8Day 9Day 10
2888121200888
3Average->9.69.69.69.69.69.6
Sheet8
Cell Formulas
RangeFormula
E3=AVERAGEIF(INDEX($A2:E2,COLUMNS($A3:E3)-COUNTIF($A2:E2,"0")-4):E2,">0")
 
Upvote 0
Day1
Day2
Day 3
D4
D5
D6
D7
D8
D9
D10
D11
D12
D13
D14
D15
D16
D17
3
7
13
12
1
0
0
6
8
12
12
9
0
0
8
8
8
9.2
9.2
9.2
9.8
10
9.8
9.8
9.4
9.4
9.4
9.166
9
9.28571
9.8
9.8
9

<tbody>
</tbody>
This appeared to work but when extending it over a much wider range it started to deviate way from the average (issue starts at Day 15, I've inserted what the value should be in row 4 from that point). Please note, I change the daily values to give more varying results

Thanks
 
Upvote 0

Book1
ABCDEFGHIJKLMNOPQ
1Day 1Day 2Day 3Day 4Day 5Day 6Day 7Day 8Day 9Day 10Day 11Day 12Day 13Day 14Day 15Day 16Day 17
2371312100681212900888
3Average->7.27.27.27.887.87.89.49.49.49.89.89
Sheet9
Cell Formulas
RangeFormula
E3=SUMPRODUCT(($A2:E2)*(ISNUMBER(MATCH(COLUMN($A3:E3)-COLUMN($A3)+1,AGGREGATE(14,6,(COLUMN($A3:E3)-COLUMN($A3)+1)^(($A2:E2)^0),{5,4,3,2,1}),0))))/5
 
Upvote 0
Apologies Nishant for not getting back sooner and thank you for your time.

I attempted to decipher your formula for some considerable time after you posted it and I still haven't got a grasp but it does work, well impressed!

Would it be possible to revise the formula so that it can average over significantly longer periods of time? For example, 120 days or even 365 days rather than just 5 days?
 
Upvote 0
Hi (and apologies Fluff for the duplicate)

Nishant94 has very kindly pulled the following formula together for me (an awesome feat in itself) and I was wondering if someone could assist taking it to the next level.


Would it be possible to revise the formula below so that it can average over significantly longer periods of time? For example, 120 days or even 365 days rather than just 5 days?


ABCDEFGHIJKLMNOPQ
1Day 1Day 2Day 3Day 4Day 5Day 6Day 7Day 8Day 9Day 10Day 11Day 12Day 13Day 14Day 15Day 16Day 17
2371312100681212900888
3Average->7.27.27.27.887.87.89.49.49.49.89.89

<tbody style="border-collapse: collapse; border-spacing: 0px 0px; font-size: 13px; margin-bottom: 0px;">
</tbody>


Worksheet Formulas
CellFormula
E3=SUMPRODUCT(($A2:E2)*(ISNUMBER(MATCH(COLUMN($A3:E3)-COLUMN($A3)+1,AGGREGATE(14,6,(COLUMN($A3:E3)-COLUMN($A3)+1)^(($A2:E2)^0),{5,4,3,2,1}),0))))/5

<tbody style="border-collapse: collapse; border-spacing: 0px 0px; font-size: 13px; margin-bottom: 0px;">
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,539
Members
449,038
Latest member
Guest1337

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