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: 14

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,225,624
Messages
6,186,066
Members
453,336
Latest member
Excelnoob223

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