Conditional Sum

L

Leslie M

I'm struggling with a difficult summation problem. My data is below. What I
need to do is...

For all records where the CT_ID is identical, if the REV TT is 0 and the REV
ACW is > 0, I need to find the next row where REV TT is not 0 and sum the REV
ACW for all of the rows above. In this example below, CT_ID 11 at 2:00 and
2:30 PM have a REV TT of 0 with a REV ACW of >0. I want to add the REV ACW
to the last non-zero value above it. This would make the 11:30 AM REV ACW
621. Then I need to make the REV ACW at 2 and 2:30 0. When all is said and
done, the total of the REV ACW for CT_ID 11 would not change, but you would
never have a REV TT of 0 in the same row as a REV ACW of >0. Thank you in
advance for your help.

Leslie

TIME CT_ID REV TT REV ACW AHT
9:00:00 AM 11 0 0 0
9:30:00 AM 11 0 0 0
10:00:00 AM 11 310 858 584
10:30:00 AM 11 361 1202 782
11:00:00 AM 11 347 30 377
11:30:00 AM 11 121 2 123
12:00:00 PM 11 0 0 0
12:30:00 PM 11 0 0 0
1:00:00 PM 11 0 0 0
1:30:00 PM 11 0 0 0
2:00:00 PM 11 0 90 90
2:30:00 PM 11 0 529 529
3:00:00 PM 11 804 574 345
3:30:00 PM 11 0 788 788
4:00:00 PM 11 0 0 0
4:30:00 PM 11 0 0 0
5:00:00 PM 11 0 0 0
9:00:00 AM 12 0 0 0
9:30:00 AM 12 0 0 0
10:00:00 AM 12 0 0 0
10:30:00 AM 12 0 0 0
11:00:00 AM 12 191 166 357
11:30:00 AM 12 0 0 0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top