I have a table TTimeRecords with records including DateofJob and HoursofWork.
DateofJob | HoursOfWork
1/1/19 | 6.0
1/2/19 | 8.0
1/2/19 | 6.0
1/3/19 | 7.0
1/3/19 | 8.0
I then wanted to create a query in which hours were summarized for 2019 on a weekly basis, with week beginning on Sunday. I have written the query like this in design view:
And it creates the datasheet view like this, which is correct:
I am running into a problem when I try to roll the query over to 2020. I copy the query with 2019 date range criteria and change it to >=#12/29/2019# And <=#12/28/2020#, then the ouput I get is:
The issue is that Week 1 of the year, 12/29/19 - 1/5/20, should total 38.25, instead of being split into two lines (week 1 = 22 and week 53 = 16.25). Additionally, the weeks 1 and 2 are now showing a Monday start.
What am I doing wrong? 12/29/19 is a Sunday with the 1st day of the next year, so I think the way I've written the formula should indicate that this is the 1st week of 2020. And it should be including hours from the rest of the week, 12/30 & onward. Also, why does week 2 start 1/6 (Monday) instead of 1/5/2020 (sunday) if I am using a "1" in the datepart function?
TIA for your help!
Edit to add: If it is helpful, here is SQL code
SELECT TEmployee.EmployeeName, DatePart("ww",[DateofJob],1,1) AS [Week of Year], DateSerial(Year([DateofJob]),1,(DatePart("ww",[DateofJob],1,1)-1)*7)-1 AS [WeekBeg (Sun)], Sum(TTimeRecords.HoursOfWork) AS SumOfHoursOfWork
FROM TEmployee INNER JOIN TTimeRecords ON TEmployee.EmployeeID = TTimeRecords.EmployeeName
GROUP BY TEmployee.EmployeeName, DatePart("ww",[DateofJob],1,1), DateSerial(Year([DateofJob]),1,(DatePart("ww",[DateofJob],1,1)-1)*7)-1
HAVING (((TEmployee.EmployeeName)=[enter name]) AND ((DateSerial(Year([DateofJob]),1,(DatePart("ww",[DateofJob],1,1)-1)*7)-1)>=#12/29/2019# And (DateSerial(Year([DateofJob]),1,(DatePart("ww",[DateofJob],1,1)-1)*7)-1)<=#12/28/2020#));
DateofJob | HoursOfWork
1/1/19 | 6.0
1/2/19 | 8.0
1/2/19 | 6.0
1/3/19 | 7.0
1/3/19 | 8.0
I then wanted to create a query in which hours were summarized for 2019 on a weekly basis, with week beginning on Sunday. I have written the query like this in design view:
And it creates the datasheet view like this, which is correct:
I am running into a problem when I try to roll the query over to 2020. I copy the query with 2019 date range criteria and change it to >=#12/29/2019# And <=#12/28/2020#, then the ouput I get is:
The issue is that Week 1 of the year, 12/29/19 - 1/5/20, should total 38.25, instead of being split into two lines (week 1 = 22 and week 53 = 16.25). Additionally, the weeks 1 and 2 are now showing a Monday start.
What am I doing wrong? 12/29/19 is a Sunday with the 1st day of the next year, so I think the way I've written the formula should indicate that this is the 1st week of 2020. And it should be including hours from the rest of the week, 12/30 & onward. Also, why does week 2 start 1/6 (Monday) instead of 1/5/2020 (sunday) if I am using a "1" in the datepart function?
TIA for your help!
Edit to add: If it is helpful, here is SQL code
SELECT TEmployee.EmployeeName, DatePart("ww",[DateofJob],1,1) AS [Week of Year], DateSerial(Year([DateofJob]),1,(DatePart("ww",[DateofJob],1,1)-1)*7)-1 AS [WeekBeg (Sun)], Sum(TTimeRecords.HoursOfWork) AS SumOfHoursOfWork
FROM TEmployee INNER JOIN TTimeRecords ON TEmployee.EmployeeID = TTimeRecords.EmployeeName
GROUP BY TEmployee.EmployeeName, DatePart("ww",[DateofJob],1,1), DateSerial(Year([DateofJob]),1,(DatePart("ww",[DateofJob],1,1)-1)*7)-1
HAVING (((TEmployee.EmployeeName)=[enter name]) AND ((DateSerial(Year([DateofJob]),1,(DatePart("ww",[DateofJob],1,1)-1)*7)-1)>=#12/29/2019# And (DateSerial(Year([DateofJob]),1,(DatePart("ww",[DateofJob],1,1)-1)*7)-1)<=#12/28/2020#));
Attachments
Last edited: