Average of the last n populated rows

schneider1972

New Member
Joined
Dec 4, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have some data that has numbers in rows. I want to calculate the average of the last 4 rows only if populated (i.e. > 0). So if a previous row is 0 I want to go back 1 additional row.

There is no pattern for when the score will be 0, I also would like to do the same theory but for the last 2 populated rows and the last 8 populated rows.

Here is a pic of what the data is like:
 

Attachments

  • Excel Question.png
    Excel Question.png
    62.3 KB · Views: 8

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hello, maybe something like:

Excel Formula:
=MAP(B2:B12,LAMBDA(x,AVERAGE(TAKE(FILTER(B2:x,B2:B2:x<>0),-4))))
 
Upvote 0
Solution
Many thanks for the feedback! Just a minor correction: the B2:B2:x part should be B2:x - a misclick on my side.
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,267
Members
452,902
Latest member
Knuddeluff

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