I am running Access 2003 and I am trying to create a running sum based on a calculated field in the query as this query builds a chart.
Here is my SQL prior to adding a DSum expression:
SELECT Left([Activity],12) AS ActivityName,
[CostSavingsperYear]/250000 AS CostReduction,
10.37 AS Target
FROM Activity
GROUP BY Left([Activity],12),
[CostSavingsperYear]/250000, 10.37
ORDER BY [CostSavingsperYear]/250000;
(The Activity field in the Table is a memo field so I am only collecting the first 12 characters as the value on the X-axis for the chart.)
I want to create a running sum of the Cost Reduction field, but am stuck on the DSum expression. I tried:
RunTotal: DSum("CostSavingsperYear/250000","Activity","Left(CostActivity,12) <= '" & Left(A.CostActivity,12) & "'")
but get these results:
ActivityName CostReduction Target RunTotal
ActivityA -------0.96 -------10.37----0.96
ActivityB -------0.96 -------10.37----3.84
ActivityC -------0.96 -------10.37----4.8
ActivityD -------1.92 -------10.37----2.88
ActivityE -------1.92 -------10.37----6.72
When the RunTotal results should be:
0.96
1.92
2.88
4.80
6.72
I read somewhere in trying to find answers that:"In order for a running sum to work correctly in a query, the recordset must have a uniqueID"
So I brought in the ID field from the table and changed the SQL to:
SELECT A.ActivityID, Left([CostActivity],12) AS ActivityName, [CostSavingsperYear]/250000 AS CostReduction, 10.37 AS Target, DSum("CostSavingsperYear/250000","Activity","ActivityID <= " & [A.ActivityID] & "") AS RunTotal
FROM Activity AS A
GROUP BY A.ActivityID, Left([CostActivity],12), [CostSavingsperYear]/250000, 10.37, DSum("CostSavingsperYear/250000","Activity","ActivityID <= " & [A.ActivityID] & "")
ORDER BY [CostSavingsperYear]/250000;
but my RunTotal results are still skewed:
2.88
3.84
4.8
1.92
6.72
Could someone offer some advice / direction to me? Thank you.
Here is my SQL prior to adding a DSum expression:
SELECT Left([Activity],12) AS ActivityName,
[CostSavingsperYear]/250000 AS CostReduction,
10.37 AS Target
FROM Activity
GROUP BY Left([Activity],12),
[CostSavingsperYear]/250000, 10.37
ORDER BY [CostSavingsperYear]/250000;
(The Activity field in the Table is a memo field so I am only collecting the first 12 characters as the value on the X-axis for the chart.)
I want to create a running sum of the Cost Reduction field, but am stuck on the DSum expression. I tried:
RunTotal: DSum("CostSavingsperYear/250000","Activity","Left(CostActivity,12) <= '" & Left(A.CostActivity,12) & "'")
but get these results:
ActivityName CostReduction Target RunTotal
ActivityA -------0.96 -------10.37----0.96
ActivityB -------0.96 -------10.37----3.84
ActivityC -------0.96 -------10.37----4.8
ActivityD -------1.92 -------10.37----2.88
ActivityE -------1.92 -------10.37----6.72
When the RunTotal results should be:
0.96
1.92
2.88
4.80
6.72
I read somewhere in trying to find answers that:"In order for a running sum to work correctly in a query, the recordset must have a uniqueID"
So I brought in the ID field from the table and changed the SQL to:
SELECT A.ActivityID, Left([CostActivity],12) AS ActivityName, [CostSavingsperYear]/250000 AS CostReduction, 10.37 AS Target, DSum("CostSavingsperYear/250000","Activity","ActivityID <= " & [A.ActivityID] & "") AS RunTotal
FROM Activity AS A
GROUP BY A.ActivityID, Left([CostActivity],12), [CostSavingsperYear]/250000, 10.37, DSum("CostSavingsperYear/250000","Activity","ActivityID <= " & [A.ActivityID] & "")
ORDER BY [CostSavingsperYear]/250000;
but my RunTotal results are still skewed:
2.88
3.84
4.8
1.92
6.72
Could someone offer some advice / direction to me? Thank you.
Last edited: