I have a table that has data organized as below:
ID Month Amount
1 1 100
1 2 125
1 3 200
1 4 210
1 5 30
1 6 70
2 1 10
2 2 37
What I need to do is have a sum which satisfies the following IF statment:
If Month > (CurrentMonth - 2) AND Month < CurrenMonth Then
Sum(Amount)
But it needs to be a running sum... meaning that I need to calculate it for month 3, 4, 5, 6, etc. Associating each sum with the given month. In English, for each month, I need to calculate the amount for the previous 3 months.
I can't think of a quick way to do it in a query or in VBA... currently, I'm using recordsets to loop through and calculate it individually, but this takes FOREVER.
Thanks,
Evan
ID Month Amount
1 1 100
1 2 125
1 3 200
1 4 210
1 5 30
1 6 70
2 1 10
2 2 37
What I need to do is have a sum which satisfies the following IF statment:
If Month > (CurrentMonth - 2) AND Month < CurrenMonth Then
Sum(Amount)
But it needs to be a running sum... meaning that I need to calculate it for month 3, 4, 5, 6, etc. Associating each sum with the given month. In English, for each month, I need to calculate the amount for the previous 3 months.
I can't think of a quick way to do it in a query or in VBA... currently, I'm using recordsets to loop through and calculate it individually, but this takes FOREVER.
Thanks,
Evan