Hi All, wondering if you someone can help me out. Can’t seem to get this, maybe its easy.
I have a table something like
flagval
1-100
1100
0100
0100
0-100
0100
1100
1-100
1100
0100
0100
1100
1100
I want to add to running total where flag is true and reduce running total where flag is false, but on the current side of the running total. So something like
Thanks Aidan, I guess close but when I run in the example I get
flagvaltoo
1-100-100
11000
0100-100
0100-200
0-100-100
0100-200
1100-100
1-100-200
1100-100
0100-200
0100-300
1100-200
1100-100
You can see on the second row, its not correct, it needs to check the side of the first row in order to be able to add to the total on the correct side
You say you want to add to the running total when flag is true but in the second row that would add 100 to -100 and give 0. But you say you expect -200?
Like Marcus, I’m not totally clear what logic you need, but whatever it is I suspect you need a custom scan function. Something like:
update total:{x+y*z}[0;val;flag] from t
This won’t give you the result you posted, but it shows how you can use the current running sum value (x in this case) along with your value and flag columns (y and z) to generate the next running sum value. Hope that helps!