If I understood correctly, try this formula in M1:
=IF(MOD(ROWS(J$1:J1),20)=18,MIN(OFFSET(J1,-17,,20,1)),IF(MOD(ROWS(J$1:J1),20)=19,MAX(OFFSET(J1,-18,,20,1)),IF(MOD(ROWS(J$1:J1),20)=0,AVERAGE(OFFSET(J1,-19,,20,1)),"")))
copied across to O1 and then down the rows to the bottom of the dataset. Every 18th to 20th row will have results.
Bookmarks