KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Accumulators – Access additional list / column Re: Accumulators – Access additional list / column

  • rocuinneagain

    Member
    September 6, 2022 at 12:00 am

    Yes in that case an accumulator is needed. One method you could choose would be to pass a table through to accumulate while also allowing you to look back to previous rows:

    q)update c2:1_@[;`c2]{y[`c2]:enlist $[(y[`c1][0]>last x[`c2]) or ((last x[`c])<last x[`c2]);y[`c1][0];last x`c2];x,y}/[enlist each {(1#0#x),x}update c2:0 from `c`c1#t] from t 
    c c1 c2 
    ---------- 
    30 10 10 
    40 20 20 
    25 5  20 
    20 25 25 
    4  5  5 
    4  4  4 
    4.5 3 4 
    4.5 3.5 4