473,385 Members | 1,730 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,385 software developers and data experts.

Calculation in report to subtract one 'group' total from Grand Total

klarae99
I am working on an Inventory Database in Access 2003. I am working on a report that I could print when its time to file our State Sales Tax paperwork. The figures I need for this report are Total Sales(not including tax), the Amount of Sales Subject to Tax, and the Total Sales Including Tax, all gathered for a specific time period.

I have a query (qrySalesTax) to find all sales within a specified date range that also calculates the Total Sales and the Total Sales Including Tax. I have a report based on the Queary that is grouped by Category, then by Month, with totals for each grouping and a Gross Total for the entire date range.

What I would like to do is to subtract the Total Sales for the category Clothing from the Gross Total Sales to arrive at the Amount of Sales Subject to Tax.

I tried creating a seperate query to calculate the Total Clothing Sales and then including it in qrySalesTax So that the Total Clothing Sales were listed seperately in the query, but the queries 'overlapped' and I got cycling listings for the clothing transactions on the same lines as the other category transactions so I abandonded this idea. I also used the Total Clothing Sales from the sepearate query as a control source for an unbound box in the footer section of the Sales Tax Report but when viewed in preview the field had only #Error displayed.

Any advice for how to do this would be appreciated. As you can probably tell I'm relatively new to this program. Also I have no real understanding of code yet so if I need to use code to facilitate this I will need some very detailed guidance. Thanks for all your help with this!
Oct 16 '07 #1
15 6129
nico5038
3,080 Expert 2GB
You're problem can only be solved by "Grouping" both queries on the same fields.
There might be a problem when for a certain Category no data is found (no sales).
This is "solved" by using a tblCategories that holds all and "outerjoin" that with the table holding the tax amounts. Making tblCategories "Master", will show zero's for the missing amounts.

Getting the idea ?

Nic;o)
Oct 17 '07 #2
Nic;o)

My lack of training is shining through again. You suggest that I "grouping" both quearies on the same field. How do you group in a queary?

Just for clarification both quearies are based on the same fields, there is just a different criteria in the Category field. (I actually created a genaric queary to find all categories for all the fields that I wanted; then I saved as to create an exact copy. Then I modified the criteria in the Category fields one only clothing and the other not clothing. I also added the prefix CLO to all the calculated fields in the Clothing only query.

From my understanding of your reply, I would create a third query to base the report on that 'grouped' both queries on the same fields.

In response to your comments on the potential problems if a category has no sales, right now tblCat is where I am storing the Category and the Tax Rate Information so I don't know how I would join them in an outer join. It seems redundant to join a table to itself. My thought would be that since they are in the same table this 'join' already exists. Is that correct?

I really appreciate your help with this!
Oct 18 '07 #3
nico5038
3,080 Expert 2GB
GroupBy queries can be created by pressing the "E" looking button.
A new line will appear above the criteria holding a combobox with "GroupBy".
All "groupingfields" should have GroupBy, but your amount should hold "Sum".
Thus you'll get for each combination of the "GroupBy" fields the sum.
Only using Categories give a sum per Category, adding an additional field will "split" the summing further.
Just try to see the effect.

Often more data is needed, but keep in mind that always a value from the combobox needs to be selected (also called "aggregation function) like Sum, Avg, Max, First, etc.

Nic;o)
Oct 18 '07 #4
Nic;o)

I should have made the connection (I think of that feature as the total feature).

I tried to combine my two queries into one query and group by sum in each of the common fields, but left the GroupBy in the fields that were unique to each query (the calculation fields). I got an expression to complicated error. Should I rename my calculation fields the same in both original queries. So that I can sum them as well? Do I need to include the category field from both queries or should I include this field from the table?

This is the first time I have tried this and am having a hard time getting my head around it all. Thanks for all your help!
Oct 18 '07 #5
nico5038
3,080 Expert 2GB
Can you post the SQL text of the queries so I can have a look ?

Nic;o)
Oct 18 '07 #6
Nic;o)

Here is the sql for the qryClothingSalesTax

Expand|Select|Wrap|Line Numbers
  1. SELECT tblCat.Categories, tblCat.TaxRate, tblTrans.TransDate, tblTrans.Sold, tblTrans.SaleDiscount, Round([Price],2) AS CloTruePrice, ([CloTruePrice]-[SaleDiscount])*[Sold] AS CloGrossSales, [CloGrossSales]*[TaxRate] AS CloTaxCollected, [CloTaxCollected]+[CloGrossSales] AS CloGrossSalesIncludingTax
  2. FROM tblEveInfo INNER JOIN ((tblCat INNER JOIN tblProd ON tblCat.CatID=tblProd.CatID) INNER JOIN tblTrans ON tblProd.Item=tblTrans.Item) ON tblEveInfo.EventID=tblTrans.EventID
  3. GROUP BY tblCat.Categories, tblCat.TaxRate, tblTrans.TransDate, tblTrans.Sold, tblTrans.SaleDiscount, tblProd.Price
  4. HAVING (((tblCat.Categories)="Clothing") And ((tblTrans.TransDate) Between [Start Date] And [End Date]) And ((tblTrans.Sold)>0));
And here is the sql for the qryNotClothingSalesTax

Expand|Select|Wrap|Line Numbers
  1. SELECT tblCat.Categories, tblCat.TaxRate, tblTrans.TransDate, tblTrans.Sold, tblTrans.SaleDiscount, Round([Price],2) AS TruePrice, ([TruePrice]-[SaleDiscount])*[Sold] AS GrossSales, [GrossSales]*[TaxRate] AS TaxCollected, [TaxCollected]+[GrossSales] AS GrossSalesIncludingTax
  2. FROM tblEveInfo INNER JOIN ((tblCat INNER JOIN tblProd ON tblCat.CatID=tblProd.CatID) INNER JOIN tblTrans ON tblProd.Item=tblTrans.Item) ON tblEveInfo.EventID=tblTrans.EventID
  3. GROUP BY tblCat.Categories, tblCat.TaxRate, tblTrans.TransDate, tblTrans.Sold, tblTrans.SaleDiscount, tblProd.Price
  4. HAVING ((Not (tblCat.Categories)="Clothing") And ((tblTrans.TransDate) Between [Start Date] And [End Date]) And ((tblTrans.Sold)>0));
And this is the qrycombinetax as it stands

Expand|Select|Wrap|Line Numbers
  1. SELECT Sum(QryNotClothingSalesTax.Categories) AS SumOfCategories, Sum(QryNotClothingSalesTax.TransDate) AS SumOfTransDate, QryNotClothingSalesTax.GrossSales, QryNotClothingSalesTax.TaxCollected, QryNotClothingSalesTax.GrossSalesIncludingTax, QryClothingSalesTax.CloGrossSales
  2. FROM QryClothingSalesTax, QryNotClothingSalesTax
  3. GROUP BY QryNotClothingSalesTax.GrossSales, QryNotClothingSalesTax.TaxCollected, QryNotClothingSalesTax.GrossSalesIncludingTax, QryClothingSalesTax.CloGrossSales;
if you need anything else let me know, I'll do my best to get it to you. Also if you need a closer look at the database you requested that I post it on the thread, Printing Multiple Copies of the a Record in The Same Report. I will be posting there shortly. Thanks for all your help with this!!
Oct 19 '07 #7
nico5038
3,080 Expert 2GB
Hmm, bit puzzled why you have this many fields in the GroupBy clause.
Also the split into "Clothing" and "Non Clothing" is a bit vague.

Can you try:
Expand|Select|Wrap|Line Numbers
  1. SELECT IIF(tblCat.Categories="Clothing","Clothing","Non Clothing") AS CategoryGroup, Round([Price],2) AS TruePrice, ((Round([Price],2)-[SaleDiscount])*[Sold]) AS GrossSales, ((Round([Price],2)-[SaleDiscount])*[Sold])*[TaxRate] AS TaxCollected, (Round([Price],2)-[SaleDiscount]*[Sold])+((Round([Price],2)-[SaleDiscount])*[Sold])*[TaxRate] AS GrossSalesIncludingTax
  2. FROM tblEveInfo INNER JOIN ((tblCat INNER JOIN tblProd ON tblCat.CatID=tblProd.CatID) INNER JOIN tblTrans ON tblProd.Item=tblTrans.Item) ON tblEveInfo.EventID=tblTrans.EventID
  3. WHERE tblTrans.TransDate Between [Start Date] And [End Date] And tblTrans.Sold>0
  4. GROUP BY IIF(tblCat.Categories="Clothing","Clothing","Non Clothing");
  5.  
and let me know the result.

Nic;o)
Oct 19 '07 #8
I entered your code into a new query and ran it. I got an error message: You tried to execute a query that does not include the specified expression 'Round([Price],2)' as part of an aggragate function. I'm not sure how to fix this.

Also I noticed that your if clause has "clothing","clothing", and "not clothing" listed. If these references are to the text in the category field than there will be an issue as "not clothing" is not a category, it was ment to mean all categories except clothing.

Maybe I am going about the whole process incorrectly. Essentially I have 8 categories, 7 of whom are taxed (all listed in tblCat with fields for CatID, Category and Tax Rate. I am trying to create a report that will tell me the total sales for all eight categories, and the amount of taxable sales (the total for the 7 categories that are taxed). What I was attempting to do with these three queries was: query 1 (Isolate sales of clothing, calculating total sales), query 2 (Isolate sales of the 7 other categories, calculating total sales and total tax collected), and query 3 (combine these two queries into one so that I could use the income from clothing indeptendent from the other categories, and preform calculation like adding the total clothing sales to the other cateogries sales to get a grand total, using only the sum of sales from the 'non clothing' categories as a taxable income amount, listing the total collected including tax, etc). Is there a better way to do this?
Oct 19 '07 #9
nico5038
3,080 Expert 2GB
Hmm, I was trying to create one query to do it all, but I guess we should start with a simplification.
Let's start with this query:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblCat.Categories, Round([Price],2) AS TruePrice, 
  2. ((Round([Price],2)-[SaleDiscount])*[Sold]) AS GrossSales, 
  3. IIF(tblCat.Categories="Clothing",0,[TaxRate])) AS GrossTaxRate
  4. FROM tblEveInfo INNER JOIN ((tblCat INNER JOIN tblProd ON tblCat.CatID=tblProd.CatID) INNER JOIN tblTrans ON tblProd.Item=tblTrans.Item) ON tblEveInfo.EventID=tblTrans.EventID
  5. WHERE tblTrans.TransDate BETWEEN [Start Date] AND [End Date] AND tblTrans.Sold>0;
  6.  
Here we calculate the "basic" fields TruePrice, GrossSales and GrossTaxRate.
To cope with the exclusion from the taxes for "Clothing" we use an IIF() to set these records to a zero TaxRate.

This query will hold one line for each "basic" record.

The next query will be a groupby (without "Clothing" selection) just specifying for the field Categories the GroupBy option in the combobox and for the GrossSales and GrossTaxRate a Sum. Finally for the GrossSalesWithTaxRate use also Sum and the calculation (GrossSales + (GrossSales * GrossTaxRate)).

Getting the idea ?

Nic;o)
Oct 19 '07 #10
Nic;o)

I still think that there might be a disconnect in the understanding of the problem, you mentioned an if clause to make the tax rate of the clothing equal 0. This is already accomplished in my table. Let me try to explain a different way, below are the tables and fields that I need to use for this report.

tblCat
CatID, autonumber, PK
Category, text
Tax Rate, number

tblProd
Item, number, PK
Price, number

tblTrans
TransID, autonumber, PK
Item, number, FK
TransDate, date
SaleDiscount, number

I want to create a query that will let me select a start and end date then calculate
For Each Category: Total Sales, Total Sales Including Tax and Total Tax Collected.

For the Report: Gross Total Sales, Gross Total Sales Including Tax, Gross Total Tax Collected and (this is the field that is causing me the issues) Total Taxable Sales. The Total Taxable sales would be equal to (Gross Total Sales - Category Clothing Total Sales).
Right now I have a report that I am using until I can get this final peice to add into it. The query is set up with the following sql

Expand|Select|Wrap|Line Numbers
  1. SELECT tblCat.Categories, tblCat.TaxRate, tblTrans.TransDate, tblTrans.Sold, tblTrans.SaleDiscount, Round([Price],2) AS TruePrice, ([TruePrice]-[SaleDiscount])*[Sold] AS GrossSales, [GrossSales]*[TaxRate] AS TaxCollected, [TaxCollected]+[GrossSales] AS GrossSalesIncludingTax
  2. FROM tblEveInfo INNER JOIN ((tblCat INNER JOIN tblProd ON tblCat.CatID = tblProd.CatID) INNER JOIN tblTrans ON tblProd.Item = tblTrans.Item) ON tblEveInfo.EventID = tblTrans.EventID
  3. GROUP BY tblCat.Categories, tblCat.TaxRate, tblTrans.TransDate, tblTrans.Sold, tblTrans.SaleDiscount, tblProd.Price
  4. HAVING (((tblTrans.TransDate) Between [Start Date] And [End Date]) AND ((tblTrans.Sold)>0));
  5.  
What I am really trying to do is to create a field on this report where I can view just the Total Income from Clothing so that I can use it in a calculation field and subtract it from the Gross Total Sales and get the Total Taxable Income.

Perhaps I just need a way to take the values calculated in my qryClothingSalesTax that I posted earlier and get that value to show in the footer of the Sales Tax Report.

I'm sorry that I can't seem to explain what I need concisely, I hope this helps!
Oct 19 '07 #11
nico5038
3,080 Expert 2GB
The GrossTotal is indeed handled by fields in the report footer.
When the TaxRate is already set to zero, then you need just one query to get the basic fields summed per category. When the taxrate can vary for the non-clothing,then you'll need first to calculate the GrossSales and GrossTax per row. Finally create the creary as described in my last comment to get the Categorie totals.

Nic;o)
Oct 19 '07 #12
I think that there is still some misunderstanding as to what I am trying to accomplish. I have opened my Sales Tax Report that is based on my basic query as I have it currently, then I published it to Word, copied and pasted the text here.

Sales Tax Report
Books September 2007
Total Sales $34.66 Total Tax $2.77 Total Sales W/ Tax $37.43
Total Category $34.66 Total Category Tax $2.77 Total Category Sales W/ $37.43
Clothing September 2007
Total Sales $167.50 Total Tax $0.00 Total Sales W/ Tax $167.50
Total Category $167.50 Total Category Tax $0.00 Total Category Sales W/ $167.50
Crystal September 2007
Total Sales $18.52 Total Tax $1.48 Total Sales W/ Tax $20.00
Total Category $18.52 Total Category Tax $1.48 Total Category Sales W/ $20.00
Gross Sales $220.68
Gross Tax Collected $4.25
Gross Sales With Tax $224.93

This is for only one month September, but when we are using real data over an extended period of time you would be able to see Septembers total sales, Octobers total sales etc. for each category.
Also you will note that some categories are not here, as there were no sales in that category over this period of time.

All of this is fine, but what I would like to do is in the report footer I would like to have a text box labled Gross Total Taxable Income. The figure for this text box in this example would be 53.18 (220.68[GrossTotalSales] - 167.50[Category Total for Clothing]) I need a way to get the Category Total for Clothing (which is a detail total in the report) onto the report footer so I can use it in calculations. Is that possible?
Oct 19 '07 #13
nico5038
3,080 Expert 2GB
For this we'll need grouping (see the =] looking button).
First add a field in the GroupBy query like:
Expand|Select|Wrap|Line Numbers
  1. Select Year(tblTrans.TransDate) & Right("00" & Month(tblTrans.TransDate),2) As YearMonth, ...
  2. [
This YearMonth field needs to be added to the Grouping and you can indicate that a Footer is needed, so Monthly totals can be specified.

When you want also a grouping for "Clothing" and "Non Clothing", the an IIF() as in one of my previous posts can be used to create another level in the query.

Getting the idea ?

Nic;o)
Oct 19 '07 #14
Nic;o)

Thanks for all your help, I really appreciate all the time you have dedicated to try and find a solution for my issue. I'll work on it some more.
Oct 22 '07 #15
nico5038
3,080 Expert 2GB
Keep me posted, I'll be happy to help you to complete the application.

Nic;o)
Oct 22 '07 #16

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

Similar topics

1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
1
by: bmoos1 | last post by:
I have two reports: 2004 New Enrollments and 2004 Cancellations. 1. Each report shows by month: "Monthly", "BiMonthly"(*2), "Weekly" (*52/12), "Total Monthly" (++) and "Projected...
3
by: Pecanfan | last post by:
Hi, I've got an access report which contains a sub-report. The sub-report contains various items in a group Footer which culminates in a running sum text box called txtGrandTotal. I want to...
6
by: jimfortune | last post by:
In: http://groups.google.com/group/comp.databases.ms-access/msg/60d7faa790c65db1 james.ea...@gmail.com said: :Ok, I've answered the first half of my own question. From a MSDN :article, I...
3
by: pat | last post by:
I'm working on a report. I have two categories (groups) with a field labeled "Amount Funded." I want to create a subtotal column (for each group) that subtracts the "Amount Funded" from a number...
4
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...
7
by: Bobh | last post by:
I am trying to figure out some code for a report issue; I have an employee who has a incentive scheme. I have a report showing various income amounts and in the report footer I vae totals for...
1
by: JCMcAbee | last post by:
Hello. Access 2003. I hope this makes sense. I request assistance with the following calculation problem: In a grouped(?) footer of the report I have the following calculations in text boxes,...
14
ollyb303
by: ollyb303 | last post by:
Hi, I am trying to create a dynamic crosstab report which will display number of calls handled (I work for a call centre) per day grouped by supervisor. I have one crosstab query (Query1) which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.