summarize by week.

ChristineMD

Board Regular
Joined
Jul 29, 2008
Messages
53
I feel like there has to be a way to do this, but I sure can't figure it out. I am using MS ACCESS 2007, linking through ODBC to a MySQL database that contains order detail.


I've written a query to summarize product sales data for a single week, via parameter entry. So user puts in their starting and ending date (so it doesn't HAVE to be a week, but it usually will be) It sums the quantity ordered and the sales price of the product. No problem.

Code:
SELECT Sum(orddetail.QuantityOrdered) AS Qty, Sum([quantityordered]*[price]) AS Demand
FROM orddetail
WHERE (((orddetail.OrderDate) Between [Start Date] And [End Date]) AND ((Left([displaysku],5)) Like "*" & [Enter Item] & "*"));


NOW, user wants to show the same info for the previous week and the following week in the same query.

I thought this would get me what I'm after, but I'm still getting just one row of results. It's also losing results. If I do individual weeks, my total qty is 251. With the query below, I'm only getting 237. Weird.

Code:
 SELECT Sum(orddetail.QuantityOrdered) AS Qty, Sum([quantityordered]*[price]) AS Demand
FROM orddetail
WHERE (((orddetail.OrderDate) Between [Start Date] And [End Date]) AND ((Left([displaysku],5)) Like "*" & [Enter Item] & "*")) OR (((orddetail.OrderDate) Between (DateAdd("w",-7,[start date])) And (DateAdd("w",-7,[end date])))) OR (((orddetail.OrderDate) Between (DateAdd("w",7,[start date])) And (DateAdd("w",7,[end date]))));

So then I tried, this... getting somewhere, but in the QBE it will not allow me to specify the first day of the week as Monday, it is treating "vbMonday" as a parameter. If I go directly to SQL view, and and try to modify the Where clause below by adding the vbMonday parameter I get an "aggregate function" error. GRRR. I think something like this, where the week number is shown would work for her, but I have to be able to say the week starts on Mon not Sun.

Code:
SELECT Sum(orddetail.QuantityOrdered) AS Qty, Sum([quantityordered]*[price]) AS Demand, DatePart("ww",[orderdate]) AS [Wk#]
FROM orddetail
WHERE (((orddetail.OrderDate) Between [start] And [end]) AND ((Left([displaysku],5)) Like "*" & [Enter Item] & "*"))
GROUP BY DatePart("ww",[orderdate])

Any suggestions will be much appreciated.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,214,986
Messages
6,122,611
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top