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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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,223,885
Messages
6,175,180
Members
452,615
Latest member
bogeys2birdies

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