I know I’ve done this before and seem to have gotten stuck again. Wondering if someone can help me out. I want to calculate a columnar value based on its previous value at some index before it.
So if I have table t
t:([]val: 10#0f)val0000000000
and I want to add 1 to the value also add the prev value, this doenst work but tried
update val:{x+y+1}\[val;prev val] from t
result would be
val12345678910
and would like to be able to have the prev value based on some index, so for example something like
update val:{x+y+1}\[val;5 xprev val] from t
val1111234567
Hope that makes sense. Basically iterating through a column and calculating the new values based on some previous index.
Thanks Callum, Terry yes I was looking more for general case because what I posted was a simlification just as an example. But how can I get the xprev value of col in this case?
but for the first iteration there is no prevFunctionResult so you can set to a value of your choosing - I assumed you would want zero. This would seed it with 1000:
update col2:{x+y+1}\[1000;col] from t
I’m not 100% clear what you’re looking for with the xprev…are you looking for:
so what am really looking for is prevFuncResult5IterationsAgo or some x number of iterations ago. So I see seeding the value with 0 works for getting prevFuncResult but I can’t seem to get anything before the prev result.
If I use
q)update col2:{x+y+1}\[0;0^1 xprev col] from t;
then value of y here is the value xprev value of col, not the xprev value of the func result, while x here is the prev value of the func result. So I guess question is it possible to get the funcResult at some x iteration ago? Or am I missing something and do you think i should go back to drawing board a bit and rethink?