Cumulative total error in query

maxmaggot

New member
Local time
Today, 20:38
Joined
Jun 22, 2013
Messages
6
Hi all,
I really need your help with a query that calculates the cumulative total spent on expenses as each month passes. Here is the query I have written:

Code:
SELECT DISTINCTROW Format(DatePart("m",[InvoiceDate]),"00") & " - " & Format(DatePart("yyyy",[InvoiceDate]),"0000") AS Expr1, Expenses.[Expense Type], Sum(Expenses.Amount) AS [Sum Of Amount], (DSum("Amount","Expenses","[Expenses].[Expense Type] <=" & [Expenses].[Expense Type])) AS [Running Total]
FROM Expenses
GROUP BY Format(DatePart("m",[InvoiceDate]),"00") & " - " & Format(DatePart("yyyy",[InvoiceDate]),"0000"), Expenses.[Expense Type]
HAVING (((Format(DatePart("m",[InvoiceDate]),"00") & " - " & Format(DatePart("yyyy",[InvoiceDate]),"0000")) Not Like "?-?"))
ORDER BY Format(DatePart("m",[InvoiceDate]),"00") & " - " & Format(DatePart("yyyy",[InvoiceDate]),"0000"), Expenses.[Expense Type];

The line that is for the cumulative total/running total is
Code:
(DSum("Amount","Expenses","[Expenses].[Expense Type] <=" & [Expenses].[Expense Type])) AS [Running Total]

I really appreciate any help and my employer is really turning the screw to get this feature to work. I just get error in the field for this query section.

I don't think I'm too far off but any help would be greatly appreciated as I can copy it into 6 more similar queries.
 
Ok I changed the query and can get results now but they are off the scale wrong.

Here is the new code
Code:
SELECT DISTINCTROW Format(DatePart("m",[InvoiceDate]),"00") & " - " & Format(DatePart("yyyy",[InvoiceDate]),"0000") AS Expr1, Expenses.[Expense Type], Sum(Expenses.Amount) AS [Sum Of Amount], Sum((DSum("Amount","Expenses",[Expense Type]<=[Expenses].[Expense Type]))) AS [Running Total]
FROM Expenses
GROUP BY Format(DatePart("m",[InvoiceDate]),"00") & " - " & Format(DatePart("yyyy",[InvoiceDate]),"0000"), Expenses.[Expense Type]
HAVING (((Format(DatePart("m",[InvoiceDate]),"00") & " - " & Format(DatePart("yyyy",[InvoiceDate]),"0000")) Not Like "?-?"))
ORDER BY Format(DatePart("m",[InvoiceDate]),"00") & " - " & Format(DatePart("yyyy",[InvoiceDate]),"0000"), Expenses.[Expense Type];

Line causing problem
Code:
Sum((DSum("Amount","Expenses",[Expense Type]<=[Expenses].[Expense Type]))) AS [Running Total]

Anyone see a solution? Thank you
 
I used a cross tab query in the end to get cumulative totals. Myself and rzw0wr where pming because I posted the db with some private info. I thanked him in those messages. The solution is a bit messy so if you want to have a look at it I can pm you the link. Thanks for responding and thanks again to rzw0wr who put a lot of effort into this.
 
If you have got the problem solved, then ok, else PM me the link and also write where there are problems.
 

Users who are viewing this thread

Back
Top Bottom