A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
... what if I wanted to average the 30 most recent entries from column B by date with the same scenario already mentioned and also add the 30 most recent entries from column B by date ...
You can hard code the 30 into the formula as you mentioned or put it into a cell and reference the cell. Let's assume that you put 30 into Z1. Your two formulas would be,
=AVERAGEIF(A:A,">="&LARGE(A:A,MIN(Z1,COUNT(A:A))),B:B)
... and,
=SUMIF(A:A,">="&LARGE(A:A,MIN(Z1,COUNT(A:A))),B:B)
You may want to tighten up those full column references (e.g. A:A, B:B to A2:A999, B2:B999) to save some processing power. You can reference cells that are blank or contain text and they will be happily skipped over byt the SUMIF() and AVERAGEIF() functions. I've added a MIN(COUNT()) function to make sure that you are not asking for more values than are available.
| AVERAGEIF function |
|---|
| SUMIF function |
| LARGE function |
| MIN function |
| COUNT function |