Filter/group/sum by month

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the most efficient way to filter or sum by month when individual
records have a date field?

I have tried this in my Where clause:

Where Month([FieldName])= Month([CriteriaDate]) AND Year([FieldName]) =
Year([CriteriaDate])

It just seems a little cumbersome to separate the month and year on both
sides, then compare against the month and year. I have considered calculating
the first/last days of each month, then doing a BETWEEN, but that might be
even more tricky.

Would it be more efficient to just generate a single number (e.g. MonthYear
of each value as Year(value)*100 + Month(value) and then compare the results?

Or is there some simple Month/Year function I have missed somewhere?
 
I searched a little farther through this forum and found the simple solution:

Format([DateField],"yyyymm")

Duh!
 
I searched a little farther through this forum and found the simple solution:

Format([DateField],"yyyymm")

Another way... one that takes advantage of any index on a date
field... uses one parameter twice:
= DateSerial([Enter year:], [Enter month:], 1) AND < DateSerial([Enter year:], [Enter month:] + 1, 1)

John W. Vinson[MVP]
 
.... and John's solution is a lot more efficient, especially if the Source
Table has many records.

--
HTH
Van T. Dinh
MVP (Access)



John Vinson said:
I searched a little farther through this forum and found the simple
solution:

Format([DateField],"yyyymm")

Another way... one that takes advantage of any index on a date
field... uses one parameter twice:
= DateSerial([Enter year:], [Enter month:], 1) AND < DateSerial([Enter
year:], [Enter month:] + 1, 1)

John W. Vinson[MVP]
 
Thank you, John.

John Vinson said:
I searched a little farther through this forum and found the simple solution:

Format([DateField],"yyyymm")

Another way... one that takes advantage of any index on a date
field... uses one parameter twice:
= DateSerial([Enter year:], [Enter month:], 1) AND < DateSerial([Enter year:], [Enter month:] + 1, 1)

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top