2

I wanted to find out a non zero weighted average from 2 arrays in google sheets - the weighted average/sumproduct should be calculated only when value in column A is not zero.

I cannot change or remove data - only a formula can solve this.

+----------+--------+
| Products | Orders |
+----------+--------+
|        5 |   1200 |
|        0 |   3497 |
|       14 |   1234 |
|       13 |    422 |
|        4 |   2444 |
|       21 |  13234 |
+----------+--------+

Desired Result = (5*1200 + 14*1234 + 13*422 + 4*2444 + 21*13234) / (1200 + 1234 + 422 + 2444 + 13234)

^^ Weights are Orders & orders where products = 0 (i.e. 2nd entry) will not be counted in the base

mark0018
  • 25
  • 4

2 Answers2

5

if weights are in A column then:

=AVERAGE.WEIGHTED(FILTER(B:B, A:A<>0), FILTER(A:A, A:A<>0))

0

player0
  • 124,011
  • 12
  • 67
  • 124
1

Basis your desire result, you can try below formula

=sumproduct((A2:A)*(B2:B))/sumif(A2:A,">0",B2:B)
Rocky
  • 950
  • 1
  • 7
  • 12