473,831 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help on Grouping by Week or DatePart function in ACCESS?

Hi, I am trying to group by week and do a count of my data in between
the dates. In Microsoft Access.

Something similar to

Before:

Date Count
--------- ---------
10/02/04 2
10/04/04 4
10/08/04 3
10/16/04 1
11/02/04 3
11/03/04 1

AFTER:

Week Of Count
--------- ----------
10/07/04 6
10/14/04 3
10/21/04 1
10/28/04 0
11/04/04 4

So I would like to start with the first week according to the earliest
date in the query. And just increase by 7 days, counting all the
values from the days. I tried to use DatePart('ww',d ate) , it didn't
work, spits out the wrong dates. Thanks in advance.
Nov 13 '05 #1
2 4556
al******@hotmai l.com (Alicia) wrote in
news:d3******** *************** ***@posting.goo gle.com:
Hi, I am trying to group by week and do a count of my data in
between the dates. In Microsoft Access.

Something similar to

Before:

Date Count
--------- ---------
10/02/04 2
10/04/04 4
10/08/04 3
10/16/04 1
11/02/04 3
11/03/04 1

AFTER:

Week Of Count
--------- ----------
10/07/04 6
10/14/04 3
10/21/04 1
10/28/04 0
11/04/04 4

So I would like to start with the first week according to the
earliest date in the query. And just increase by 7 days,
counting all the values from the days. I tried to use
DatePart('ww',d ate) , it didn't work, spits out the wrong
dates. Thanks in advance.


Create a function that returns the weekending date, then call
that in the query.

Public function WEDate(Actual as variant) as variant.
if isdate(actual) then
WEDate = dateadd("d",act ual,7-weekday(actual) )
end if
end sub

But that will not return the row 10/28/04 0
For that you will need to create a calendar table and right join
that to your existing data.

Bob Quintal
Nov 13 '05 #2
"Alicia" <al******@hotma il.com> wrote in message
news:d3******** *************** ***@posting.goo gle.com...
Hi, I am trying to group by week and do a count of my data in between
the dates. In Microsoft Access.

Something similar to

Before:

Date Count
--------- ---------
10/02/04 2
10/04/04 4
10/08/04 3
10/16/04 1
11/02/04 3
11/03/04 1

AFTER:

Week Of Count
--------- ----------
10/07/04 6
10/14/04 3
10/21/04 1
10/28/04 0
11/04/04 4

One way to solve these problems is by using a pre-loaded calendar table to
hold the temporal information with the groupings that you need.

create table weeks
(
weekstart datetime not null primary key,
weekend datetime not null
)

insert into weeks(weekstart , weekend) values (#09/30/04#, #10/07/04#)
insert into weeks(weekstart , weekend) values (#10/07/04#, #10/14/04#)
insert into weeks(weekstart , weekend) values (#10/14/04#, #10/21/04#)
insert into weeks(weekstart , weekend) values (#10/21/04#, #10/28/04#)
insert into weeks(weekstart , weekend) values (#10/28/04#, #11/04/04#)

select w.weekstart, sum(a.[Count]) as newCount
from weeks as w
left outer join alicia as a on w.weekstart > a.[Date]
and w.weekend <= a.{Date]
group by w.weekstart



Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5228
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much appreciated. TIA
3
1638
by: NewmanBT | last post by:
As you can see from the code below, several textboxes will be dynamically created and each will be tied to an org. The ChangeComment function should allow for an update to the database whenever the value of the associated textbox changes. However, I'm having trouble associating the textbox to the org. strOrg is a global variable which changes throughout the runtime. How do I capture its value at each stage a textbox is created so that...
9
7292
by: PamelaDV | last post by:
I have two problems, actually. I am looking to see if there is a function that will return the day of the week (Monday, Tuesday, Wednesday, etc...) from a date. For instance 2/27/04 is a Friday. Also is there a way to group dates by week? I have a user who wants a report to group by week. I know I could create a table and assign dates to a week, but I'm wondering if anyone has anything out there already done that may be a little bit...
4
2567
by: Mark Reed | last post by:
Hi all, I am using office XP and have a question regarding the format function. I am using wk:format(.,"WW") to show what week a certain date is. The problem is that a week runs from Sun to Sat in Access and our warehouse week runs from Sat to Fri. This is making my "week to date" calculations a day out. Is there a way that I can specify which day a new week starts on within this query???? Many thanks in advance,
4
1744
by: Alicia | last post by:
I am having a problem grouping by week. I am looking for the simpliest way of doing it in Microsoft Access. I have tried to use a pre-loaded calender, access did not like it at all. If there is another way of counting the number of ProblemCounts with a single week, by using DatePart etc. Give me a shout. Thanks. Something similar to Before:
5
3042
by: Peter Bailey | last post by:
I have a query that returns , and : 12/05/04 3 Wednesday 13/05/04 0 Thursday and so on what I would like to do now is count the number of bookings by week so from monday to friday from the first date get the sum of bookings.
10
3903
by: Ty Smith via AccessMonster.com | last post by:
I noticed that the week numbers in Stephan Leban's MonthCalendar are not consistent with Microsoft Outlook (they are shifted one week forward). Is there any way I can sync these two up by changing something in the module or the code in Stephan's MonthCalendar? Thanks, TySmith -- Message posted via http://www.accessmonster.com
3
5878
by: Bob | last post by:
I wish to group data on a report by week, month and year. Crystal reports has this ability as a built in function. Is there a quick way to do this in Access97/2000 VBA reports ? Thank you in advance, Bob.
9
2553
by: Cliff | last post by:
I want to use the Datepart function to determine the week number based on my company's fiscal calendar which starts Nov. 1. I have tried the following and they all produce #ERROR# . DatePart("ww",!,2,"11/01/2005") DatePart("ww",!,2,#11/1/2005#) If leave the Nov 1 date out, I get a result that appears to be based on Jan 1 as the date. It also appears to be the week number in the year, such that Jan 1 in 2005 and 2006 both have a week...
0
9793
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10494
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10207
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9317
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5619
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.