问题
I want to find out the average cost of an apple, the price isn't always filled out, I know I should be able to do this with sumproduct, but it's not working for me.
A B
Fruit Price
Apple 56
Banana 23
Apple
Apple 40
Apple
My problem comes when I try to count how many apples have a price value entered. Can anyone help?
Note: I'm using Excel 2003 hence no countifs
回答1:
So you expect to get 48 as the average for Apple?
Two possible ways.....
An array formula with AVERAGE
=AVERAGE(IF(A2:A10="Apple",IF(B2:B10<>"",B2:B10)))
confirmed with CTRL+SHIFT+ENTER
....or use SUMIF/SUMPRODUCT
=SUMIF(A2:A10,"Apple",B2:B10)/SUMPRODUCT((A2:A10="Apple")*(B2:B10<>""))
来源:https://stackoverflow.com/questions/19299160/calculating-average-of-specific-values