# Running totals

#### Pettor

##### Board Regular
Hello guys,

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?

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
28.8 KB · Views: 1
Last edited by a moderator:

### 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
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:

Replies
7
Views
205
Replies
3
Views
180
Replies
1
Views
270
Replies
10
Views
229
Replies
11
Views
1K

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.

### Which adblocker are you using?

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

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