Average all the values that are not 0 and a max of 23 values, but get all the non 0s (there will be a max of 23)

Tej92

Board Regular
Joined
Sep 27, 2022
Messages
73
Office Version
  1. 365
Platform
  1. Windows
Hello all, i currently have this formula that averages the values from S50:AL999 if the finds CN21 in the range P50:P999.
i need this formula to take all the values that are not 0, there will be a max of 23 (cell reference CR21) values to average that are not 0, i need it to average all the values and add 0s until the total number isn't 23, if it goes over 23 values not 1s they need to averaged too.
is this possible?
=AVERAGE(FILTER($S$50:$AL$999,$P$50:$P$999=$CN21))
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Please provide some sample data and expected results. Please be sure to include different scenarios (i.e. at least one case where you have 23 non-zero values and, one that you do not have 23 non-zero values).

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
I was trying to work through your word problem and then got lost...could you provide some data?

Doug
 
Upvote 0
I'm really sorry for the bad explanation, here is an example, with the expected output at the bottom.
I need it to take all the values that are not 0, then the 0s until the total number is 23 values. once 23 is reached it stops taking 0 into the average formula.
if there are more then 23 values that are not 0 it needs to take them too.
hopefully this is clearer.

ABC
0​
60​
0​
70​
0​
40​
0​
0​
0​
0​
0​
0​
0​
0​
80​
80​
70​
70​
20​
20​
10​
10​
20​
20​
80​
80​
70​
70​
20​
20​
10​
10​
20​
20​
80​
0​
70​
0​
20​
0​
10​
0​
20​
0​
80​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
0​
70​
0​
70​
0​
70​
0​
0​
0​
0​
0​
0​
0​
average
38.69565​
24.78261​
 
Upvote 0
How about
Excel Formula:
=LET(f,FILTER(B1:B42,B1:B42<>0),IF(ROWS(f)>=23,AVERAGE(f),AVERAGE(EXPAND(f,23,,0))))
 
Upvote 0
@Fluff I'm really sorry that in the last response i forgot to write down that it needs to reference to a cell (let's use CN21) and only take values from the adjacent ranges like in this formula:
=AVERAGE(FILTER($S$50:$AL$999,$P$50:$P$999=$CN21))
this formula needs to be adjusted
 
Upvote 0
In that case please use the XL2BB add-in to post some realistic data.
 
Upvote 0
I'm really sorry for the trouble, add-ins are disabled for security reasons, is there any other way to look at the data, without uploading any files?
 
Upvote 0
In that case just paste the data the same way you did before.
 
Upvote 0

Forum statistics

Threads
1,215,136
Messages
6,123,243
Members
449,093
Latest member
Vincent Khandagale

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