Running totals

Pettor

Board Regular
Joined
Aug 8, 2015
Messages
164
Hello guys,

Another question about running totals.

I run the below query where I want to calculate the running total up to a date where a specific condition is being met i.e. Action = X.
It works up to a point, but when it finds another value (see the list where value is "0") instead of bringing again the same number and continue from that number, it goes to the next one and has added also the 0 filed to the final total. I know it is the sum function but I can't think of a better way to do it.

Any opinion?

Thanks in advance

SQL:
SELECT DATE, PERSON, ACTION
(SELECT Sum(IIf(T1.ACTION="X",1,0)) FROM Results WHERE T1.MDATE >= MDate AND T1.PERSON = PERSON) AS ACTIONS
FROM DB AS T1
ORDER BY DATE, PERSON;
 

Attachments

  • tempsnip1.jpg
    tempsnip1.jpg
    28.8 KB · Views: 1
Last edited by a moderator:

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Pettor

Board Regular
Joined
Aug 8, 2015
Messages
164
Hi guys, I just figured it out. I had to delete the T1. from the inside query! Sorry for the trouble! I hope it will work now!


SQL:
SELECT MDATE, PERSON, ACTION
(SELECT Sum(IIf([COLOR=rgb(184, 49, 47)]ACTION="X",1,0[/COLOR])) FROM Results WHERE T1.MDATE >= MDate AND T1.PERSON = PERSON) AS ACTIONS
FROM DB AS T1
ORDER BY MDATE, PERSON;
 
Last edited by a moderator:
Solution

Watch MrExcel Video

Forum statistics

Threads
1,127,588
Messages
5,625,664
Members
416,124
Latest member
DeMoNloK

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top