=AVERAGE(OFFSET(P3,,MATCH(1E+100,P3:AAD3)-A1,1,3)) where a1 contains the number of last cells you want to average