Average first n non-zero results in a row

gooniegirl180

Board Regular
Joined
Aug 13, 2003
Messages
152
I have a row of dates from row C5:U5.
In column A are a list of products: column B contains a "Switch", Column C contains an average, and column W may or may not contain start date.

If the switch for a product is AVG, I want the result in column X to be the figure in column C. Easy.
If the switch for a product is FOR, I want the result in column X to be the average of the first 8 non-zero columns. Doable.
If the switch for a product is PRE, I want the result in column X to be the average of the first 8 non-zero columns from (and including) the start date onwards. If there are less than 8 non-zeros, such as in example G below, I want the average of the number of non-zero values. There may be any number of zero values from the start date before the values kick in, but I still want the average of the first 8 values.

Any help would be gratefully received! Thanks!

1717739537991.png
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
If you have 365, then:

Excel Formula:
=IFS(B2="AVG",C2,B2="FOR",AVERAGE(TAKE(FILTER(D2:V2,D2:V2<>0),,8)),B2="PRE",AVERAGE(TAKE(FILTER(D2:V2,($D$1:$V$1>=W2)*(D2:V2<>0)),,8)))
 
Upvote 0
Solution
For your PRE product something like
Excel Formula:
=IF(COUNTIF(A1:M1,">0")>=8,AVERAGE(INDEX(FILTER(A1:M1,A1:M1<>0),SEQUENCE(1,8))),AVERAGE(FILTER(A1:M1,A1:M1<>0)))
Adapt ranges as required
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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