Search code examples
kdb

How to calculate weighted average in window join?


Is there a way to calculate weighted average in a window join (wj) Since we can use min, max, avg there should be a way to use wavg too?

wj[w; `sym`time; tbl; (data; (wavg; `quantity; `price))]

This just gives me a list of values preceded by wavg


Solution

  • This is the 2 step workaround.

    update price: quantity wavg' price from wj[w; `sym`time; tbl; (data; (::; `price); (::; `quantity))];