I am trying to create a formula that giving me the average of the last 15 or 20 rows in a spreadsheet based upon multiple conditions.

The formula below works however it is not based upon any conditions.
=AVERAGE(OFFSET(E$7,COUNT(E7:E129)+1-S133,0,S$133))

S133 is the cell that will determine how many rows (last rows), so if I wanted the average of the last 15 rows I would input 15 in cell S133.

I tried the below averageifs formula where it should look for "GIS Take-UP" in rows $D$6:$D$129 and then give an average of the last 15 rows ( or whatever value is input in S133) where the "GIS Take-Up" is present however the below formula does not work.

=AVERAGEIFS(OFFSET(E$7,COUNT(E7:E129)+1-S133,0,S$133),$D$6:$D$129,"GIS Take-Up")

Can anybody help me solve this problem it would be very much appreciated.

Thanking everyone in advance for all your help.

K