Ignore Trailling Zeros in an Average

MutanGFX

New Member
Joined
Aug 25, 2022
Messages
11
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello!

I have the following row with data:

0 0 0 1 6 4 2 0 1 0 0 3 4 5 3 2 3 1 0 0 0 0

I'm currently using the flowing formula to ignore leading zeros from the average:

=AVERAGE(INDEX($A$2:$V$2,1,MATCH(TRUE,INDEX($A$2:$V$2<>0,),0)):$V$2)

But I also need to ignore the trailling zeros, but I have no idead how to perform the same trick from right to left to find the first cell <>0

Any help will be much appreciated.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
MrExcelPlayground11.xlsx
ABCDEFGHIJKLMNOPQRSTUV
10001642010034532310000
22.3333
3
400045670900121314151617180000
54567912131415161718
64
718
8164201003453231
92.3333
Sheet17
Cell Formulas
RangeFormula
A2A2=LET(r,A1:V1,a,(r>0)*SEQUENCE(1,COLUMNS(r)),b,FILTER(a,a>0),c,MIN(b),d,MAX(b),e,INDEX(r,1,SEQUENCE(1,d-c+1,c)),AVERAGE(e))
A4:V4A4=(A1:V1>0)*SEQUENCE(1,COLUMNS(A1:V1))
A5:L5A5=FILTER(A4#,A4#>0)
A6A6=MIN(A5#)
A7A7=MAX(A5#)
A8:O8A8=INDEX(A1:V1,1,SEQUENCE(1,A7-A6+1,A6))
A9A9=AVERAGE(A8#)
Dynamic array formulas.
 
Upvote 0
MrExcelPlayground11.xlsx
ABCDEFGHIJKLMNOPQRSTUV
10001642010034532310000
22.3333
3
400045670900121314151617180000
54567912131415161718
64
718
8164201003453231
92.3333
Sheet17
Cell Formulas
RangeFormula
A2A2=LET(r,A1:V1,a,(r>0)*SEQUENCE(1,COLUMNS(r)),b,FILTER(a,a>0),c,MIN(b),d,MAX(b),e,INDEX(r,1,SEQUENCE(1,d-c+1,c)),AVERAGE(e))
A4:V4A4=(A1:V1>0)*SEQUENCE(1,COLUMNS(A1:V1))
A5:L5A5=FILTER(A4#,A4#>0)
A6A6=MIN(A5#)
A7A7=MAX(A5#)
A8:O8A8=INDEX(A1:V1,1,SEQUENCE(1,A7-A6+1,A6))
A9A9=AVERAGE(A8#)
Dynamic array formulas.

I have no idea how any of this works but thank you
 
Upvote 0
MrExcelPlayground11.xlsx
ABCDEFGHIJKLMNOPQRSTUV
10001642010034532310000
22.3333
3
400045670900121314151617180000
54567912131415161718
64
718
8164201003453231
92.3333
Sheet17
Cell Formulas
RangeFormula
A2A2=LET(r,A1:V1,a,(r>0)*SEQUENCE(1,COLUMNS(r)),b,FILTER(a,a>0),c,MIN(b),d,MAX(b),e,INDEX(r,1,SEQUENCE(1,d-c+1,c)),AVERAGE(e))
A4:V4A4=(A1:V1>0)*SEQUENCE(1,COLUMNS(A1:V1))
A5:L5A5=FILTER(A4#,A4#>0)
A6A6=MIN(A5#)
A7A7=MAX(A5#)
A8:O8A8=INDEX(A1:V1,1,SEQUENCE(1,A7-A6+1,A6))
A9A9=AVERAGE(A8#)
Dynamic array formulas.
For some reason both of the above solutions are only working for the first row of data (I have multiple rows where I need to achieve the same result, average ignoring the first and last zeros)

The error is just #CALC!

Would you know how to solve that?
 
Upvote 0
It's just one solution - I have the compact LET formula, and then I break it out into all of the steps so you might follow what is happening (teach a man to fish...)

Here it is setup differently so you can put in multiple rows of this stuff:
MrExcelPlayground11.xlsx
ABCDEFGHIJKLMNOPQRSTUVW
1300016420100345323100002.333333
1400006420100345323100002.428571
1500006420100345323100002.428571
1600516420100345323104002.444444
1754016420100345323100042.181818
18012016420100345323105002.736842
1900016420100345323100002.333333
Sheet17
Cell Formulas
RangeFormula
W13:W19W13=LET(r,A13:V13,a,(r>0)*SEQUENCE(1,COLUMNS(r)),b,FILTER(a,a>0),c,MIN(b),d,MAX(b),e,INDEX(r,1,SEQUENCE(1,d-c+1,c)),AVERAGE(e))
 
Upvote 0
Solution
It's just one solution - I have the compact LET formula, and then I break it out into all of the steps so you might follow what is happening (teach a man to fish...)

Here it is setup differently so you can put in multiple rows of this stuff:
MrExcelPlayground11.xlsx
ABCDEFGHIJKLMNOPQRSTUVW
1300016420100345323100002.333333
1400006420100345323100002.428571
1500006420100345323100002.428571
1600516420100345323104002.444444
1754016420100345323100042.181818
18012016420100345323105002.736842
1900016420100345323100002.333333
Sheet17
Cell Formulas
RangeFormula
W13:W19W13=LET(r,A13:V13,a,(r>0)*SEQUENCE(1,COLUMNS(r)),b,FILTER(a,a>0),c,MIN(b),d,MAX(b),e,INDEX(r,1,SEQUENCE(1,d-c+1,c)),AVERAGE(e))

Thank you again!

It was my mistake, some of the rows had just 0's in them, hence the #CALC!, so I added and IFERROR(formula;0) and now everything works!
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,164
Members
448,870
Latest member
max_pedreira

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