also @ TechSpot: Motorola Droid 4 unboxing, hands-on video
Welcome to the TechSpot OpenBoards. Please read the FAQ if you have any questions. Sign up or Login to participate.

Go Back   TechSpot OpenBoards > Software > Software Apps

Collaborate in the cloud with Office, Exchange, SharePoint, and Lync

Need help with MS Access

Thread Tools Search this Thread
  #1  
Old 05-25-2004
Newcomer, in training
 
Location: Columbus, OH
Member since: Aug 2003, 1 posts
Need help with MS Access

I have a table of daily sales revenue for the past 3 years. I need to do a query that will calculate weekly sales revenue for each year and compare it to the same week in the prior years. Anyone have any ideas on this?

Thanks,
Brian
  #2  
Old 05-29-2004
TechSpot Addict
 
Location: Jefferson City, MO, USA
Member since: Oct 2002, 703 posts
I would suggest breaking the table into three tables- one for each year.

Then run a query to sum a range between 1/1 and 1/7. Then 1/1+7, 1/7+7.. Probably do this with vba. Take those results, put them in a table or array, and do the same for each year. Compare results with vba as the final part of a query form.


Just my two cents- lots of nice in theory things here, but depending on your usage you'll probably be banging your head to do that.

Keeping in mind that there are 52 weeks per year, just do sums for each 7 day period, give it a week number. Then compare against week X, week x+52, week x+2*52, etc.. That would work in a single table, but you still gotta store results for a bit.

BTW- Welcome to techspot!
  #3  
Old 05-29-2004
Nic's Avatar
Nic Nic is offline
TechSpot Paladin
 
Location: UK
Member since: Jan 2003, 1,918 posts
Select the sales figure for the year and subtract the previous year's figure using a subselect where year = year - 1. Group by week. Something like that. Be more specific and post the table/column names if you want more useful help.
  #4  
Old 05-29-2004
MrGaribaldi's Avatar
TechSpot Ambassador
 
Location: Babylon 5, Grid Epsilon
Member since: Feb 2002, 2,802 posts
I too was thinking along similar lines of Goalie, but I'd just skip the last table, and do the math in the query.

Takes up a bit less space that way

Dunno why you'd need VBA though. I'd think that'd just make it harder, as all you've got to do with the regular commands is to mulitply the rows (or columns) with 7..

Here's a little Excel style sample (dunno if it's the same in Access, as it's over 4 years since I used it last. And it's only 3 since I used excel). (you'll either need to get at the index number, or have a column for week/index which can be accessed)
Code:
=((B$(A$1*7))+(B$((A$1*7)+1))+(B$((A$1*7)+2))+(B$((A$1*7)+3))+(B$((A$1*7)+4))+(B$((A$1*7)+5))+(B$((A$1*7)+6)))
At least that's how I think it'd be, since the number in the A column would increase with one, as you drag it downwards (still thinking excel, but it shouldn't be too hard to convert), thus giving you the correct address in the B column on which to add together. You'd still need to add in the code for what table to get the data from though...


BTW: Sorry if the example is wrong, but I'm tired, had a bit to drink and haven't used excel nor access in several years. But the logic behind it should still be applicable.