473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Create Totals and Sub Totals in a Query

58
I’m trying to get some calculations in a Query. Four fields are from a table x, and base on those fields I need to get some combination of Totals. This is the scenario.

Total A : [field 1]+[field 2] from table x
Total B : [field 3]+[field 4] from table x

So far so good. I don’t have any problem to have totals until this point. My question is: how can I create these next calculations.

Total C : (Total A) / (Total B)
Total D : (Total B) * (Total C)

If anyone can help me with any ideas for completing this task I would be really grateful.

Plaguna
Jul 17 '08 #1
2 2275
Stewart Ross
2,545 Expert Mod 2GB
Hi Plaguna. You should check by substitution that you are not causing yourself unnecessary work here. From your definitions Total D is just Total A:

Total D = Total B * Total C
Total C = Total A / Total B, therefore
Total D = Total B * (Total A / Total B) = Total A

In a previous post we looked at how to calculate percentages of question respondents, and the approach is similar here.

It is simplest to devise a query which calculates your totals A and B, then use this to feed another query:

Expand|Select|Wrap|Line Numbers
  1. SELECT[list of all fields you are grouping on], [field 1] + [field 2] 
  2. AS [Total A], [field 3] + [field 4] as [Total B] 
  3. FROM [your table]
  4. GROUP BY[list of all fields you are grouping on], [field 1] + [field 2], [field 3] + [field 4]
After you save this query you can then use it in other queries to do the calculation of Total C.

Alternatively, if you want to do this all in one query you will need to substitute for Total A and Total B by performing the field additions repeatedly:

Expand|Select|Wrap|Line Numbers
  1. SELECT[list of all fields you are grouping on], [field 1] + [field 2] As [Total A], [field 3] + [field 4] as [Total B], (([field 1]+[field 2])/([field 3 + field 4])) as [Total C]
  2. FROM [your table]
  3. GROUP BY[list of all fields you are grouping on], [field 1] + [field 2], [field 3] + [field 4], (([field 1]+[field 2])/([field 3 + field 4]))
It is easiest to use the Access query editor to assist you with this, selecting View, Totals to set the grouping on, then adding calculated fields as necessary.

-Stewart
Jul 18 '08 #2
plaguna
58
Stewart,

Thank you again. I didn’t realize the redundancy of Total D. You saved me a lot a headaches. It’s so much flexible working with SQL statements. It works perfectly. I really appreciate it.

Plaguna
Jul 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
2
by: deko | last post by:
I have a number of queries that pull totals from different tables. How do I sum the different total values from each query to get a grand total? I tried using a Union query like this: SELECT...
4
by: New Guy | last post by:
I'm trying to work with a system that somebody else built and I am confounded by the following problem: There is a table of payments and a table of charges. Each client has charges and payments...
2
by: BerkshireGuy | last post by:
I have the following code: Dim strSQL As String Dim DB As DAO.Database Dim RS As DAO.Recordset Dim intNumOfPaid, intNumOfHypoed, intNumOfNotTaken, intNumOfDeclined, intNumOfWasted,...
2
by: BerkshireGuy | last post by:
I have a form that acts like a dashboard to show summarized data. Currently, this form gets its summarized values from a total's query. When the user selects to run the dashboard, they should be...
4
by: Micheal | last post by:
Greetings Access Group, Being relatively new to Access, I try to work through problems on my own and have been very successful, although I have a conundrum that I have been working on for two days...
8
by: elias.farah | last post by:
Hello Everyone, I'm having some very weird behavior on a couple of Access forms. (Not all forms, just some of them). The forms have been working for years, under Access XP/2003 etc, and last...
2
by: Fresco | last post by:
On large invoices, it's better cash flow at times to pay only part now, part later. I tried using a totals query to build a recordset that show a listing of invoices that have balances owing with...
5
by: colin spalding | last post by:
How do I design a totals query that instead of the following result YearOfAcc PremiumGBP 2004 9,142,306.95 2004 1,481,153.21 2005 11,981,987.85 2006 20,653,195.20 2006 ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.