Re: Proper Query Summing
- From: salad <oil@xxxxxxxxxxx>
- Date: Sat, 24 Mar 2007 16:01:45 GMT
dancole42@xxxxxxxxx wrote:
So I have an invoicing database based on two main forms: Orders and
OrderLines. Orders has fields like:
OrderID
BillingMethod
OrderDate
CreditCard
CCExp
OrdSubTotal
ShippingCharge
SalesTax
OrdTotal
OrderLines has fields like:
LineID
ProductType
Product
Price
Quantity
LineSubtotal
OrderID (relates back to OrderID in orders)
The ProductType field is a combo box based on a table called TypeList
that lists all the different types of products we offer, along with
what Department sells each product. Each Department only sells their
own type of Products, so you won't ever see an invoice with products
from multiple departments.
So on the Orders form, users can enter the basic order info and in the
OrderLines subform they enter as many different products as they want
on the invoice.
The Order table is linked to a separate Batch table so that all the
invoices for a particular day are entered into that day's invoice
batch.
Access 101, right? My problem comes with a report I want to run.
At the end of the day, I want a report based on a query that will show
me how much money was brought in by each Department.
So I set up my query with the Orders, OrderLines, and TypeList tables.
I relate the OrderIDs between the two Order Tables, and the
ProductTypeIDs between the OrderLines and TypeList tables.
I set up a where statement so only Orders from the current day's batch
appear in the query. This works fine. The problem is, I tell it to
Group By the Department field in the TypeList table, and Sum the
OrdTotal field from the Orders table. However, it's clearly
calculating many of the orders TWICE. When I turn off the query's
TOTALS option, I get a Select query that looks something like this:
Department OrdTotal
Database Subscription $995.00
Online $49.95
Online $49.95
Research $151.69
Research $151.69
Research $151.69
Online $49.95
Online $49.95
Online $49.95
Research $200.44
Research $200.44
Research $200.44
Research $200.44
Research $200.44
Research $134.64
Research $134.64
Research $134.64
Clearly it doesn't like the fact that I'm grouping by a value in one
table and trying to sum the values in another table.
Although you gave a detailed description of your problem it wasn't an adequate description.
What is the above? Detail? Is it correct? Do you want to see detail? Or summary in the report? Or both?
If you use a nonTotals query are the results correct? Or are there duplicates?
If you build a report you can set it up to be a summary report or detail report.
I think you'd be better off creating a Select query than a Totals query.
If you have incorrect results, perhaps you've designed the query wrong. But then, we don't see the SQL statement so we'd just be guessing.
.
So how SHOULD I be doing this?
Thanks!
- Follow-Ups:
- Re: Proper Query Summing
- From: dancole42
- Re: Proper Query Summing
- References:
- Proper Query Summing
- From: dancole42
- Proper Query Summing
- Prev by Date: Re: Open form using where clause
- Next by Date: Re: Hide Captions title on form windows
- Previous by thread: Proper Query Summing
- Next by thread: Re: Proper Query Summing
- Index(es):
Relevant Pages
|