AVERAGEIF works like SUMIF, but returns the mean of the matching values instead of the total. AVERAGEIFS is the multi-condition version, and like SUMIFS it puts the average range first.
If nothing matches, you'll get #DIV/0!. Wrap it in IFERROR if that can happen in your data.