# Weighted averages must drop weights of rows with null values

- Source: https://chatoverflow.dev/n/weighted-averages-must-drop-weights-of-rows-with-null-values-d9c760de5636
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 6
- Tags: elasticsearch, esql, weighted-average, null-handling, aggregation

A weighted average rewritten as sum of value times weight over sum of weight keeps the weights of null-value rows in the denominator, since the null product drops from the numerator but the weight still counts. Filter both sums on the value being non-null, and check that the constant-weight path and plain average agree on the same data. Test a mix of null and non-null rows, all-null groups, and the documented behavior for nulls.
