View Full Version : Group by Month problem


Lanser
04-13-2010, 03:42 AM
I have a report (.jpg attached)some data in a table sorted by a couple of queries and I need to list by month and shift I also need to sort it by year but despite mucho searching I haven't been able to do it, so I would be grateful for any pointers/help

here is the record source

SELECT DISTINCTROW Format$([qryWelfareMshiftTest].[Date],'mmmm yyyy') AS [Date By Month], qryWelfareMshiftTest.Shift, Avg(qryWelfareMshiftTest.Hockburn) AS [Avg Of Hockburn], Avg(qryWelfareMshiftTest.BreastBlisters) AS [Avg Of BreastBlisters], Avg(qryWelfareMshiftTest.GreenLeg) AS [Avg Of GreenLeg], Avg(qryWelfareMshiftTest.BruisedBreast) AS [Avg Of BruisedBreast], Avg(qryWelfareMshiftTest.BruisedWing) AS [Avg Of BruisedWing], Avg(qryWelfareMshiftTest.BrokenWing) AS [Avg Of BrokenWing], Avg(qryWelfareMshiftTest.BruisedLeg) AS [Avg Of BruisedLeg], Avg(qryWelfareMshiftTest.BrokenLeg) AS [Avg Of BrokenLeg], Avg(qryWelfareMshiftTest.Foot_Lesions) AS [Avg Of Foot_Lesions]
FROM qryWelfareMshiftTest
GROUP BY Format$([qryWelfareMshiftTest].[Date],'mmmm yyyy'), qryWelfareMshiftTest.Shift, Year([qryWelfareMshiftTest].[Date])*12+DatePart('m',[qryWelfareMshiftTest].[Date])-1
ORDER BY Year([qryWelfareMshiftTest].[Date])*12+DatePart('m',[qryWelfareMshiftTest].[Date])-1;

SOS
04-13-2010, 02:51 PM
For Sorting and Grouping in reports you need to do it within the report's SORTING AND GROUPING and not within the query.

Lanser
04-14-2010, 07:59 AM
Hmm I tried doing it via the report and with a rolling year it would sort on the month not on the year so it woul go Jan 2010, Feb 2010 March 2010, April 2009, May 2009 etc