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 (ie 2nd entry) will not be counted in the base
Basis your desire result, you can try below formula
=sumproduct((A2:A)*(B2:B))/sumif(A2:A,">0",B2:B)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.