Biff (T. Valko) came up with the following worksheet function solution. Please notice that you have to enter this formula as an array formula. You need to enter it with CTRL + SHIFT + ENTER, not only with ENTER:
In cell D7: =IF(COUNTIF($A$2:$A$99,$C7)<D$6,"",AVERAGE(IF(ROW($A$2:$A$99)>=LARGE(IF($A$2:$A$99=$C7, ROW($A$2:$A$99)),D$6),IF($A$2:$A$99=$C7,$B$2:$B$99))))
