I am preparing a report that takes an export of work items and determines which items can be done in a given year based on a given amount of funding. Essentially, my export is a list of work items that need to be done and I need to see which items can be completed if I had, for example, $100K that year. I know that the report function of Access can give me a running sum, but I need this in a query form because it will actually be a subquery.
The table is called "tblWorkingData" and the fields are WorkItemID (this is an autonumber for each record in the table), LICost (this is how much the work item will cost), and Score (this prioritizes the work items based on another algorithm in the database where the work items are created). I need a running total of LICost. Currently, DSUM is calculating the LICost multiplied by the record number.
Here's the query (in SQL form):
SELECT tblWorkingData.WorkItemID, Sum(tblWorkingData.[ACTUAL COST]) AS LICost, tblWorkingData.SCORE, DSum([LICost],"tblWorkingData","[WorkItemID] <=" & [WorkItemID]) AS RunTotal
FROM tblWorkingData
GROUP BY tblWorkingData.WorkItemID, tblWorkingData.SCORE
ORDER BY tblWorkingData.SCORE DESC;
And here's the current output:
WorkItemID LICost SCORE RunTotal 30 330 77.2207792207792 330 31 475 77.2207792207792 950 32 610 76.1818181818182 1830 33 2250 75.1428571428571 9000 34 7300 74.1038961038961 36500 35 3800 72.1818181818182 22800 36 4000 72.1818181818182 28000 37 4000 72.1818181818182 32000 38 3800 72.1818181818182 34200 39 4000 72.1818181818182 40000 40 4000 72.1818181818182 44000 41 9900 71.1428571428572 118800 42 9300 71.1428571428571 120900 43 222000 70.987012987013 3108000 44 28500 70.1038961038961 427500 45 2300 69.2207792207792 36800 46 614000 61.0649350649351 10438000 47 65 55.9350649350649 1170 48 950 52.5714285714286 18050 49 950 52.5714285714286 19000 50 65 47.7922077922078 1365 51 65 47.7922077922078 1430 52 65 47.7922077922078 1495 53 65 47.7922077922078 1560 54 65 47.7922077922078 1625 55 65 40.3896103896104 1690 56 65 40.3896103896104 1755 57 65 40.3896103896104 1820 58 65 40.3896103896104 1885
So although WorkItemID starts at 30, it is Record #1 and the Dsum has multiplied the LICost by the record number. You can see this as early as WorkItemID 31. The LICost is 475 and dsum has returned 950 (475 x 2).
How do I change the criteria portion of the dsum statement to start performing the running total correctly?