I need to create a query that produces running totals for every group within my table for example i wish to see: -
Group A
[running total] 1
[running total] 5
[running total] 9
[running total] 15
Group B
[running total] 1
[running total] 2
[running total] 20
etc..
I have worked out how to produce a running total but this will produce it for all records in the table and not split it (or reset it when it find a new group). Also this method works on the Unique ID which will fail due to the grouping required.
16 11320 PEB 1,418
Recognized Expert Top Contributor
Hi,
Try to do a query that do the sum by your wanted groups and make Union query with your not aggregate query
:)
Thanks for that, I think I understand what you mean!!
But if I sum by group and then run a query on the results, won't that just give me the running total of the groups?
I am looking to list all records by group with all the fields in each group showing a running total. After I have achieved that I only want to see records in ech group that reach a certain value.
Thanks again
PEB 1,418
Recognized Expert Top Contributor
You mention that u've done the running total! How did you do it?
Maybe we can integrate sth with this?
:)
I used a sql query to create an alias and then compared ID with ID : -
SELECT tbl_Alias.group s, tbl_Alias.id AS Expr1, (SELECT Sum([table3].[totals]) AS Total
FROM [table3]
WHERE ((([table3].[ID])<=[tbl_alias].[ID]));) AS [Running Total], tbl_Alias.total s
FROM table3 AS tbl_Alias, Table3
GROUP BY tbl_Alias.group s, tbl_Alias.id, tbl_Alias.total s;
This wirks by creating a running total based on my unique ID field however I need to do this on the records within each group.
Any Ideas??
PEB 1,418
Recognized Expert Top Contributor
So it seems to be reachable using VB functions and a temporary table to store the results! This is the way that I see!
Do u want to proceed in this direction?
I will be using the results as a transfer to MS Excel (the only reason I am using Access is because of the amount of rows required (over 65000 records). I will be happy to use any method avaliable.
PEB 1,418
Recognized Expert Top Contributor
So this have to be pasted into a module in Access: -
Global last_criteria
-
Global last_used
-
-
Function Set_last(Values, criterias)
-
last_criteria = nts(criterias)
-
last_used = nts(Values)
-
Set_last = last_used
-
End Function
-
-
Function show_last(Ref)
-
'Stop
-
show_last = last_used
-
End Function
-
Function show_last_criteria(Ref)
-
show_last_criteria = last_criteria
-
End Function
-
For running sum for a Group your column should be:
Run_sum: IIF(show_last_c riteria([Group_Name])=[Group_Name],Set_last(val(s how_last([Group_Name]))+ [myvalues],[Group_Name]),Set_last([myvalues], [Group_Name]))
So you need to change in this expression:
[Group_Name] with the name of the field that contains your groups
And
[myvalues] with the Field on which you are running sum
From query choose make table query and give the name of the table in which will be stored the result!
Than choose Run and open the respective table!
:)
Thanks for the script, however I am getting a sub or function not defined.. with the nts highlighted??
I have removed the nts references so now it looks like: -
Function Set_last(Values , criterias)
last_criteria = criterias
last_used = Values
Set_last = last_used
End Function
the code runs okay but my resulting table is duplicating the running sum?
i.e.
id totals Run_sum groups
1 0.2 0.4 group1 (added 0.4 instead of 0.2)
2 0.2 0.8 group1 (added 0.4 instead of 0.2)
3 0.5 1.8 group1 (added 1.0 instead of 0.5)
4 0.7 3.2 group1 etc...
5 0.8 4.8 group1
6 0.2 5.2 group1
7 0.5 6.2 group1
8 0.1 0.2 group2
9 0.1 0.4 group2
10 0.1 0.6 group2
11 0.1 0.8 group2
12 0.1 1 group2
13 0.1 1.2 group2
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: NotGiven |
last post by:
I have two tables, Client and Project, related by clientID.
I want to display a table with total CURRENT projects and total COMPLETED
projects per client.
I'd like for it to show like this:
Client Name Current Proj Completed Proj
Stan's Dormers 4 12
Larry Lincoln Dealership 2 1
|
by: Pedro Fonseca |
last post by:
Greetings!
Can someone please help me to crack this problem? I have 4 tables:
Subject, Forum, Topic and Post. A Subject groups various Forums, a
Forum groups various Topics, and a Topic groups several Posts. The
references inside the tables are:
+-----------+ +-----------+ +-----------+ +-----------+
| Subject | | Forum | | Topic | | Post |
+-----------+ +-----------+ +-----------+ +-----------+
|
by: Tom |
last post by:
I have a report based on a crosstab query that shows monthly automobile sales.
The report is grouped on Make so that it shows the models under each Make. I
want to now get the subtotals by Make and then the total for all for each month.
I find that the control source for the textboxes in the detail section have a
date value such as Jan_03 rather than dollars but when I run the report dollars
appears in the report. Obviously I can't sum up...
|
by: nick.leggin |
last post by:
I have a recordset that includes the following data
Location
Territory
Sales
Total Sales
% of total sales
A location can have multiple territories, and each territory has
different sales
|
by: lorirobn |
last post by:
Hi,
I have a report displaying items that are missing from a room. I
created 2 queries, the first getting the items IN the room, and the
second being an "unmatched" query that references the first query
where Item is Null. I use a subreport for the details, and the
results display correctly.
However, the Report_Details event of the subreport is executed about 2
or 3 times more than I would expect (I think 3 times when I have a
| |
by: nico3334 |
last post by:
I have a database that has a Date column (1/1/2007) and a Data column that has numerical data. I am currently running a query to sum the Data column for a certain month and grouped by day (There is more than items of Data for a specific Day). Here is my current query:
SELECT SUM(Data) as Total
FROM database
WHERE Month(Date) = 10
And Year(Date) = 2007
Group by Day(Date)
This displays the summed data which is grouped by the Days of...
|
by: silversubey |
last post by:
I am using a query to total hours (Cltbudget.CBudhours) and dollars (CltBudget.CBudFee) Grouped by client names (Cltbudget.CBudCltName).
here is the Query:
SELECT CltBudget.CBudCltName AS Client
, SUM(CltBudget.CBudfee) AS 'Total Dollars'
, SUM(CltBudget.CBudhours) AS 'Total Hours'
FROM VPM.dbo.CltBudget CltBudget, CltDue
WHERE CltBudget.CBudDueID = CltDue.CDID AND ((CltDue.CDTarget Between '01-01-2007' And '12-31-2008')
AND...
|
by: odavison |
last post by:
I'm currently running a crosstab query that displays the total amounts of Appointments that each Consultant.
Currently it is Consultant ID as the Rows, and Appointment Date as the top headings, grouped by Date (rather than month etc.)
But it is giving me a random order of dates going up numerically by day and no more.
Is there any way of giving an order to the Date columns or specifying that is should be for the next 7 days etc? here...
|
by: beacon |
last post by:
Hello to everybody,
I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know), but each answer is given a different point value for each question.
For instance, question 1 might ask "Do you like candy?" and if you answer Yes you will get +1, No will earn you -1, and Don't know will net you zero points. The next question might...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |