Link to home
Start Free TrialLog in
Avatar of Kai Lee
Kai Lee

asked on

Running Sum Help

Hello Experts,

I used report for running sum. But right now I need running sum by tool number in query to create a graph. I have been trying for days. Tool number is text, shiftend is date, and output is number. Please help I need to have this demo out by next week. User generated image
Avatar of Kai Lee
Kai Lee

ASKER

And I keep getting #error with this RunningSum: Val(DSum("Tool Number","Shifts","Tool Number='" & [Tool Number] & "' And ShiftEnd <= #" & [ShiftEnd] & "#"))
try using the COUNT and GROUPING functions is sql
start with the summing query type (sigma)
Avatar of Kai Lee

ASKER

I am sorry I am kind new to Access.
This is my sql looks like right now
SELECT Shifts.ShiftID, Shifts.[Tool Number], Shifts.ShiftEnd, Shifts.[Output_Tools/Shift], Val(DSum("Tool Number","Shifts","Tool Number='" & [Tool Number] & "' And ShiftEnd <= #" & [ShiftEnd] & "#")) AS RunningSum
FROM Shifts
GROUP BY Shifts.ShiftID, Shifts.[Tool Number], Shifts.ShiftEnd, Shifts.[Output_Tools/Shift];
Avatar of Kai Lee

ASKER

I used Grouping. What is summing query type?
once you have the group by (which is different to your image above), you are on the right path.
do you want the count of each tool type? I dont really understand what you want.
also, if you upload the database I can look at the query
it sounds like count of tools by day? i.e. grouped by date and tool number?

it also looks as if you are posting multiple threads for the same issue?
Avatar of Kai Lee

ASKER

Yea I changed few things. I attached images. Sorry I have to cover up some data,User generated imageUser generated image
Avatar of Kai Lee

ASKER

lol I want to know if there is another way I can create a graph just in case this one doesn't work for me. But I really appreciate your help.
do you want the count of tools by day? please explain the requirement
once you have the query defined you can use Excel to create the graphs (if Access doesn't cut it)

using VAL( of tool numbers gives a very different result to COUNT
Avatar of Kai Lee

ASKER

I want running sum of output by tool number and day.
Avatar of Kai Lee

ASKER

Something like this but by tool number User generated image
i.e. SUM output GROUP BY tool number and day

SUM output assumes many output records for each tool?
Avatar of Kai Lee

ASKER

yes
so we are done?
Avatar of Kai Lee

ASKER

my running sum is still not working User generated image
Avatar of Kai Lee

ASKER

I want to know what cause the error
you didn't display the error.

you would use the SQL SUM function, not your own.
and you don't group by WHERE fields

Please  upload the database.
I have a BIG problem: I cannot design databases once I have logged onto https://www.experts-exchange.com because the SSL url clashes with Trusteer rapport and slows Access to a crawl.
So I cannot do both (design your databases and correspond on EE).

If no-one else can solve these issues then I will get a 2nd machine configured and look at the issues later
Avatar of Kai Lee

ASKER

yea that is fine.
In the mean time it would be helpful if you explained exactly what you want in plain text.

e.g.
'I want to see the sum of 'output' for each shift and tool'

1. is the 'running sum' actually a running sum (accumulating as it goes) , or just the total of output grouped by toolnumber and shift ('day')?
2. does the same toolnumber occur many times in a shift?
3. does the exact same shiftend date occur for all tools in a day (is that why you are grouping by shift end?)? if the date/time varies you will get multiple shift- groups in a day

THE DATABASE YOU SENT HAS NO SHIFT TABLE OR RELATED FIELDS. I HAVE TO GO TO MEETINGS NOW, BUT WILL MONITOR EMAILS PERIODICALLY TO SEE IF YOU HAVE SUPPLIED THE CORRECT DATABASE AND ANSWERS TO THE QUESTIONS REGARDING ACTUAL REQUIREMENTS.
Avatar of Kai Lee

ASKER

Just in case you don't know what a running sum means. A running total is the summation of a sequence of numbers which is updated each time a new number is added to the sequence, by adding the value of the new number to the previous running total.

i want to see the running total of output for each tool. I showed something similar in previous comment.

 User generated image
Avatar of Kai Lee

ASKER

This is grouped by PLS and a running sum of percentage.
You haven't sent the database yet but the following is some sql for you to start with. You will need to substitute field names where mine are invalid.

SELECT Shift1.[Tool Number], Shift1.[Output], SUM(Shift2.[Output]) AS Running_Total
FROM Shift Shift1, Shift Shift2
WHERE Shift1.[Output] <= Shift2.[Output] or (Shift1.[Output]=Shift2.[Output] and Shift1.[Tool Number] = Shift2.[Tool Number])
GROUP BY Shift1.[Tool Number], Shift1.[Output]
ORDER BY Shift1.[Output] DESC, Shift1.[Tool Number] DESC;
Avatar of Kai Lee

ASKER

I checked the database i sent. I am sure there is a shifts table and a running sum query. i will try this sql . Thanks.
Avatar of Kai Lee

ASKER

Why there are shift1 and shift2 two tables in sql? I only have one table. Can you take a look at the attachment that i posted in previous comments? I don't really understand this one.
as I have stated 3 times, your attachment contained no 'shift' table - I don't even know if this is the correct database.
see image below.

There are two shift tables needed in the query to generate the running totals. both are aliases of the original shift table. I have not tested the query because I don't have the table and data.
User generated image
ASKER CERTIFIED SOLUTION
Avatar of COACHMAN99
COACHMAN99

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kai Lee

ASKER

Thank you. I know how you did it. That is pretty clever.