Solved

group by week access

Posted on 2011-03-23
7
344 Views
Last Modified: 2012-05-11
Hello experts.

I have grouping by week in my report.
I need show in group header date range for each week instead number of week what I have right now.

Existing formula (showing number of week in year):
=formula$[(Date Worked)],"ww",0,0)

I' looking something like that instead:
Running report for march 2011
week 03-01-2011 thru 03-05-2011
detalis......
week ......etc
how to do that
thx
0
Comment
Question by:henryk123
  • 4
  • 2
7 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35199150
Yeah, I did this once in a previous Q....

I'll dig it up tonight if another Expert does not chime in...


JeffCoachman
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 35199491
I have a table (tbl_Numbers) that I use for this purpose.  It contains a single field (intNumber) and 10 records (the values 0 through 9).  From this table, I create a query (qyr_Numbers) which generates numbers from 0 through 99 (easy to expand to 999 or larger) that looks like:

SELECT Tens.intNumber * 10 + Ones.intNumber as intNumber
FROM tbl_Numbers as Tens, tbl_Numbers as Ones

from qry_Numbers, you can then create another query which gives you the week start and end dates for a given 100 day period (given the start date).

SELECT DatePart("ww",DateAdd("d",[intNumber],[StartDate])) AS RangeWeek,
            Min(DateAdd("d",[intNumber],[StartDate])) AS WeekStart,
            Max(DateAdd("d",[intNumber],[StartDate])) AS WeekEnd
FROM qry_Numbers
WHERE Weekday(DateAdd("d",[intNumber],[StartDate]),2)<6
GROUP BY DatePart("ww",DateAdd("d",[intNumber],[StartDate]));
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35199600
Thanks fyed, mine was much more convoluted than yours...

;-)

Jeff
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35199633
henryk123,

Just keep in mind that anytime you do things "Weekly", you need to take into account the year.

For example, if your data spans multiple years, you could have week 12 for *all* years, in the same Group.

Jeff
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35199640
...so your primary grouping should be the Year, then the week...
0
 
LVL 44

Expert Comment

by:GRayL
ID: 35199657
Can you confirm you want to do this for a given month for data to date in the current year?
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 35199862
If you modify my query slightly,  you could limit it to a particular week.  It would look something like:

PARAMETERS [StartDate] DateTime, [MyWeek] Short;
SELECT DatePart("ww",DateAdd("d",[intNumber],[StartDate])) AS RangeWeek,
             Min(DateAdd("d",[intNumber],[StartDate])) AS WeekStart,
             Max(DateAdd("d",[intNumber],[StartDate])) AS WeekEnd
FROM qry_Numbers
WHERE Weekday(DateAdd("d",[intNumber],[StartDate]),2)<6
 AND DatePart("ww",DateAdd("d",[intNumber],[StartDate]))=[MyWeek]
GROUP BY DatePart("ww",DateAdd("d",[intNumber],[StartDate]));

You could then use this query (call it qry_Dates) and create a function that would wrap that up and return the string for the header group header.

Public Function fnWeekStartAndEndDates(MyYear as integer, MyMonth as integer, MyWeek as integer) as String

    Dim dtStartDate as Date
    Dim qdf as dao.querydef
    Dim rs as DAO.Recordset

    dtStartDate = dateserial(MyYear, MyMonth, 1)
    set qdf = currentdb.querydefs(qry_Dates)
    qdf.parameters(0) = dtStartDate
    qdf.parameters(1) = MyWeek

    set rs = qdf.openrecordset
    if rs.eof then
        fnWeekStartAndEndDates = "Invalid combination of Year, Month, and week!"
    Else
        fnWeekStartAndEndDates = "Report running for " & format(dtStartDate, "mmmm yyyy") & " week " _
                                                  & Format(rs(1), "mm-dd-yyyy") & " thru " & Format(rs(2), "mm-dd-yyyy")
    End If

    rs.close
    set rs = nothing
    set qdf = nothing

End Function

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now