Using Date functions to convert Daily Dataset to Monthly

Dear all,

I previously posted a question about converting a daily dataset to weekly.  See the below answer.

Select DateAdd("d", -Weekday([DateField]), [DateField]) as WeekStart,
          District, Sum([Loss]) as WeekLoss, Sum([Hectare]) as WeekHectare, 
          Sum([Count]) as WeekCount
FROM yourTable
GROUP BY DateAdd("d", -Weekday([DateField]), [DateField]) as WeekStart, District

Open in new window


I've tried to adjust the query to convert my daily dataset to monthly dataset (calendar months mm/yyyy ) without success.  My attempt is below.  I changed the DateAdd method interval to month "m" instead of day "d" and updated the Weekday function to the Month function however it still aggregates according to the weekly dataset and changes only the starting month.  I must be missing something?

Select DateAdd("m", Month([DateField]), [DateField]) as WeekStart,
          District, Sum([Loss]) as WeekLoss, Sum([Hectare]) as WeekHectare, 
          Sum([Count]) as WeekCount
FROM yourTable
GROUP BY DateAdd("m", Month([DateField]), [DateField]) as WeekStart, District

Open in new window


Thanks
AndyC1000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chaauCommented:
With monthly report you need to use just Month() on its own.
Select Month([DateField]) as MonthOfYear,
          District, Sum([Loss]) as MonthLoss, Sum([Hectare]) as MonthHectare, 
          Sum([Count]) as MonthCount
FROM yourTable
GROUP BY Month([DateField]), District

Open in new window

0
Rey Obrero (Capricorn1)Commented:
try this query


Select Format([DateField]"yyyy-mm") as monthstart,
          District, Sum([Loss]) as monthLoss, Sum([Hectare]) as monthHectare,
          Sum([Count]) as monthCount
FROM yourTable
GROUP BY Format([DateField]"yyyy-mm"), District
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.