Brian Sowter
asked on
Revenue and volume by type number
I have an access 360 data base of about 10000 orders. Each record (order) shows the type number ordered, the quantity and total price. Only one type number per order. How can I make a query which shows the total revenue and quantity by type number?
ASKER
Could you please get me started with groups. I already have revenue as a field. I have generated a table of type numbers
That could be a query like:
Select
[type number],
Sum([quantity]),
Sum([revenue])
From
YourTable
Group By
[type number]
ASKER
CAN I DO THIS WITH CROSSTAB?
You can use GROUP BY and various aggregate functions to create a query. For example, to SUM by Quantity over a specific Group:
SELECT SUM(SomeField) FROM YourTable GROUP BY YourGroupField
In your case, if you want to sum the quantity:
SELECT [Type Number], SUM(Quantity) FROM YourOrdersTable GROUP BY [Type Number]
To get the Revenue:
SELECT [Type Number], SUM(Quantity * UnitPrice) FROM YourOrdersTable GROUP BY [Type Number]
Of course you'd have to change Table and Column names to match your project.
SELECT SUM(SomeField) FROM YourTable GROUP BY YourGroupField
In your case, if you want to sum the quantity:
SELECT [Type Number], SUM(Quantity) FROM YourOrdersTable GROUP BY [Type Number]
To get the Revenue:
SELECT [Type Number], SUM(Quantity * UnitPrice) FROM YourOrdersTable GROUP BY [Type Number]
Of course you'd have to change Table and Column names to match your project.
ASKER
Hi Gustav
Forgive my ignorance...Does this mean I must write the SQL code rather than use the Query designer?
Forgive my ignorance...Does this mean I must write the SQL code rather than use the Query designer?
That's up to you.
Open a new query, go to SQL view, paste the code, and edit it to match you table and field names.
Then you can switch to the design view to study.
Open a new query, go to SQL view, paste the code, and edit it to match you table and field names.
Then you can switch to the design view to study.
ASKER
This is my code:
SELECT SUM([Qty]) FROM Query1 GROUP BY [Type]
SELECT [Type], SUM([Qty]) FROM Query1 GROUP BY[Type]
SELECT [Type], SUM([Value] FROM Query1 GROUP BY [Type]
I get "Syntax error in query expression '[Type] SELECT [Type]" after saving
SELECT SUM([Qty]) FROM Query1 GROUP BY [Type]
SELECT [Type], SUM([Qty]) FROM Query1 GROUP BY[Type]
SELECT [Type], SUM([Value] FROM Query1 GROUP BY [Type]
I get "Syntax error in query expression '[Type] SELECT [Type]" after saving
You can only have one Select in a normal query.
See my query above.
See my query above.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to everybody who helped. It is working well now!
You're welcome.
If you want to run this across all orders, you would use the above calculation and group by Type Number, excluding all other columns.