HeyI'm trying to get running totals by date while using a filter column to determine if I should add or subtract the current row with the previous row. I am not sure how to approach this without using a cursor. The data looks like this:tID gID tran_date balop amount3272 5841816 12/14/2013 1 673281 5841816 12/14/2013 0 03296 5841816 12/28/2013 1 49.373301 5841816 12/28/2013 -1 1003402 5841816 12/29/2013 1 6.063409 5841816 1/13/2014 1 56.423459 5841816 1/13/2014 0 03488 5841816 1/16/2014 1 10.583516 5841816 1/16/2014 -1 50
I need to use the "balop" filter to determine how to determine what the running total is on each rowRules:when balop = 0 then "total" = carry forward the prev. row amount when balop = 1 then "total" = prev. row amount + current row amountwhen balop = -1 then "total" = current row amount - prev. row amount
The the output should end up like this:tID gID tran_date balop amount Total3272 5841816 12/14/2013 1 67 67 *1st transaction row3281 5841816 12/14/2013 0 0 67 *prev. row amount3296 5841816 12/28/2013 1 49.37 116.37 *prev. row amount + current row amount3301 5841816 12/28/2013 -1 100 16.37 *current row amount - prev. row amount3402 5841816 12/29/2013 1 6.06 22.43 *prev. row amount + current row amount3409 5841816 1/13/2014 1 56.42 78.85 *prev. row amount + current row amount3459 5841816 1/13/2014 0 0 78.85 *prev. row amount3488 5841816 1/16/2014 1 10.58 89.43 *prev. row amount + current row amount3516 5841816 1/16/2014 -1 50 39.43 *current row amount - prev. row amount
So if I wanted to know the running total on 12/28/2013, I would like to return 16.37 (because tID = 3301 is the last transactionID on that day)What would be the best way to attack this?Thanks