with helper columns to give days 1-365 col f and one to count non null values col g then use averageif as in col e (note its an array formula confirmed with ctrl+shift+enter)
if you dont want the extra column g
use
=IF(SUMPRODUCT(--(B1:B8760=F1),--(D1:D8760<>-9999))>21,AVERAGE(IF(B1:B8760=F1,D1:D8760)),"less than 22 non null values") in col e instead (again array entered)
see my sig on how to enter arrays
Bookmarks