Returning average of the first N NON-zero values (incl neg values) of a column

AIK8888

New Member
Joined
Dec 6, 2018
Messages
8
Hello

New to the forum. I was wondering if somebody could be so kind as to help me with the following, which I have struggled with for hours now wihtout finding a solution to.

I am trying to derive a function which generates the average of the first N non-negative values of a columns.

Example column (where N=5):

0
2
3
0
0
0
-5
3
7
0
0
8

For the column above, the calculation would be [2+3+(-5)+3+7]/5 = 2

Many, many thanks in advance!
 
If you have a formula in the relevant range, let that formula not return real 0's. Return text e.g., NA instead.

Thanks Aladin - I will do that.
Would you also have any suggestions on how to adjust the formula if the range does not start in A1? Say B12 or whatever... Thank you!!
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
...obvisously just changing the cell references to A10:A50 "should" do it, but for some reason the calculations are off when I try that...

Is this what you want?

Control+shift+enter, not just enter:

=AVERAGE(IF(ROW(A2:A50) <= SMALL(IF(ISNUMBER(1/A2:A50),ROW(A2:A50)),MIN(C1,SUM(IF(ISNUMBER(1/A2:A50),1)))),IF(ISNUMBER(1/A2:A50),A2:A50)))

If you adopt NA instead of 0...

=AVERAGE(IF(ROW(A2:A50) <= SMALL(IF(ISNUMBER(A2:A50),ROW(A2:A50)),MIN(C1,SUM(IF(ISNUMBER(A2:A50),1)))),IF(ISNUMBER(1/A2:A50),A2:A50)))
 
Last edited:
Upvote 0
Is this what you want?

Control+shift+enter, not just enter:

=AVERAGE(IF(ROW(A2:A50) <= SMALL(IF(ISNUMBER(1/A2:A50),ROW(A2:A50)),MIN(C1,SUM(IF(ISNUMBER(1/A2:A50),1)))),IF(ISNUMBER(1/A2:A50),A2:A50)))

If you adopt NA instead of 0...

=AVERAGE(IF(ROW(A2:A50) <= SMALL(IF(ISNUMBER(A2:A50),ROW(A2:A50)),MIN(C1,SUM(IF(ISNUMBER(A2:A50),1)))),IF(ISNUMBER(1/A2:A50),A2:A50)))


YES!!!

Wow. I am impressed. Thank you so, so much!!!!
 
Upvote 0

Forum statistics

Threads
1,216,105
Messages
6,128,859
Members
449,472
Latest member
ebc9

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