Say I have a spreadsheet with 18 rows, and I can hard code the range of the last 7 values in column D and average their values like so:
=AVERAGE(D12:D18)
How then could I do the same without hard coding them, so it'll work as I add more rows?
If you want to calculate the average or sum, there's no need for a script. You can accomplish this with an array filter as well. The following formula calculates the average over the last 7 rows in the A column:
=AVERAGE(FILTER(A:A;ARRAYFORMULA(ROW(A:A)>COUNT(A:A)-7+1)))
This assumes that the data starts at row 1. Otherwise you have to change the latter constant in the formula to the row number where the data starts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With