我已经读过这可能是不可能的/我只是做错了所以我想知道是否有人知道解决方法(非VBA)或可以纠正我?谢谢!
Col A has the price of apples and oranges
Col D has apples and Oranges
Col E has the type of fruit (Red, Yellow, Green, Purple)
我正在努力获得Col A的平均值,其中Col D是苹果,而Col E是红色或黄色。
我试过了:
=SUM(AVERAGEIFS(A:A,D:D,"Apples",E:E,"Red"),AVERAGEIFS(A:A,D:D,"Apples",E:E,"Yellow"))/2
但它不起作用 - 任何人都有任何想法?
答案 0 :(得分:2)
是的,你可以这样做:
=SUM(SUMIFS(A:A,D:D,"Apples",E:E,{"Red","Yellow"}))/SUM(COUNTIFS(D:D,"Apples",E:E,{"Red","Yellow"}))
使用Enter
修改 公式比较
答案 1 :(得分:2)
我认为你不能在AVERAGEIFS
中添加OR操作,但你可以使用它(它是一个数组公式,所以你必须用ctrl + shift + enter输入它):
=AVERAGE(IF((D:D="Apples")*((E:E="Yellow")+ (E:E="Red")),A:A))
如果您不想使用数组公式(作为@JvdV答案的替代方法),您可以使用:
=SUMPRODUCT(A:A,--(D:D="Apples"), --((E:E="Red")+(E:E="Yellow")))/SUMPRODUCT(--(D:D="Apples"), --((E:E="Red")+(E:E="Yellow")))
答案 2 :(得分:2)
与JvdV的回复类似,您可以直接使用AVERAGEIFS。
=AVERAGE(AVERAGEIFS(A:A, B:B, {"a","c"}))
'for your data
=AVERAGE(AVERAGEIFS(A:A,D:D, "Apples", E:E, {"Red","Yellow"}))
<强>附录:强>
4.00 apples Red
2.70 oranges Purple
2.13 apples Purple
2.64 apples Yellow
3.11 apples Purple
2.96 apples Purple
9.44 apples Yellow
2.07 oranges Red
3.14 oranges Purple
3.58 oranges Yellow
2.44 oranges Red
2.82 apples Red
2.86 apples Yellow
2.23 oranges Yellow
1.95 apples Red
2.37 oranges Yellow
以上样本数据产生以下相同的结果:
=AVERAGE(A2,A5,A8,A13,A14,A16)
=AVERAGE(AVERAGEIFS(A:A,D:D,"apples",E:E,{"red","yellow"}))
=SUM(SUMIFS(A:A, D:D, "apples", E:E, {"red","yellow"}))/SUM(COUNTIFS(D:D, "apples", E:E, {"red","yellow"}))
但是,当{OR}条件中有不同数量的匹配时,结果会有不良结果。
4.00 apples Red
2.70 oranges Purple
2.13 apples Purple
2.64 apples Yellow
3.11 apples Purple
2.96 apples Purple
9.44 apples Yellow
2.07 apples Red
3.14 oranges Purple
3.58 oranges Yellow
2.44 oranges Red
2.82 apples Red
2.86 apples Yellow
2.23 oranges Yellow
1.95 apples Red
2.37 oranges Yellow