Forum Discussion
Hr
Oct 20, 2022Copper Contributor
Averageifs function divide by zero error
I trying to get the correct average of just the q1 and q3 values using averageifs function. Have looked a lot online but couldn't find a solution. However, someone kindly did help me here on MS commu...
- Oct 20, 2022That is due to the empty cells in your data, to cater for those we need an additional check:
=AVERAGE(IF((H2:H13<>"")*((G2:G13="Q1")+(G2:G13="Q3"))>0,H2:H13,""))
JKPieterse
Oct 20, 2022Silver Contributor
The AVERAGEIFS function always uses AND, so all conditions in the function must be met, for a value to be counted in. To have an OR condition, you simply add two AVERAGEIFS functions:
=AVERAGEIFS(H2:H13,G2:G13,"q1")+AVERAGEIFS(H2:H13,G2:G13,"q3")
The formula will return #DIV/0! if q1 and/or q3 is not in your data.
=AVERAGEIFS(H2:H13,G2:G13,"q1")+AVERAGEIFS(H2:H13,G2:G13,"q3")
The formula will return #DIV/0! if q1 and/or q3 is not in your data.
- HrOct 20, 2022Copper ContributorHello Jan Karel Pieterse,
Thanks for your reply, now the averageifs function makes sense to me. However, I got the correct average by making some changes in your formula: =(AVERAGEIFS(H2:H13,G2:G13,"q1")+AVERAGEIFS(H2:H13,G2:G13,"q3"))/2.
Do you know if there is simpler formula/function to compute such a problem (say with more than 2 criteria) or know somewhere I can find/ask?- JKPieterseOct 20, 2022Silver ContributorOuch, I treated this as if it were a SUMIFS, it's an AVERAGEIFS. Those -of course- cannot simply be added :-). I'm also not convinced your divide two is valid.
I see two alternatives:
=AVERAGE(IF((A1:A44="q1")+(A1:A44="q2")>0,B1:B44,""))
or
=(SUMIFS(B1:B44,A1:A44,"q1")+SUMIFS(B1:B44,A1:A44,"q2"))/(COUNTIFS(A1:A44,"q1")+COUNTIFS(A1:A44,"q2"))- HrOct 20, 2022Copper Contributor
JKPieterse perhaps you can try divide by two yourself since I am indeed getting the correct average with that but just think the formula is too long. Also, after trying your two alternatives:
1. =AVERAGE(IF((G2:G13="q1")+(G2:G13="q3")>0,H2:H13," "))
2. =(SUMIFS(H2:H13,G2:G13,"q1")+SUMIFS(H2:H13,G2:G13,"q3"))/(COUNTIFS(G2:G13,"q1")+COUNTIFS(G2:G13,"q3"))
I get 18,847 for both, instead of the correct average which is 56,540.5.