By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,588 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,588 IT Pros & Developers. It's quick & easy.

variable grouping in Access

P: 10
I was hoping someone could tell me if Access can do variable grouping in a report or query. I have a table that just has the ages of a group of people. I would like to produce a report or even just a query that gives me a count of the ages grouped like this:
0-3
4-12
13-18
19+

If Access can do this, can you tell me how please? Thanks for any help!
May 22 '07 #1
Share this Question
Share on Google+
2 Replies

puppydogbuddy
Expert 100+
P: 1,923
I was hoping someone could tell me if Access can do variable grouping in a report or query. I have a table that just has the ages of a group of people. I would like to produce a report or even just a query that gives me a count of the ages grouped like this:
0-3
4-12
13-18
19+

If Access can do this, can you tell me how please? Thanks for any help!
Yes, Access can do this (see below). I did this in two steps. For step #1, I created a query to setup the groupings and place each raw data item in the applicable group. The in step #2, I used the above query as the source for a crosstab query to summarize the counts by group/

[font=Tahoma][size=3]Source (Base) Query[/size][/font]

[font=Tahoma][size=3]__________________________________________________ ______________________[/size][/font]

[font=Tahoma][size=3]SELECT Age.Age, IIf([Age] Between 0 And 3,"0-3",IIf([Age] Between 4 And 12,"4-12",IIf([Age] Between 13 And 18,"13-18","19+"))) AS AgeGroup, Count(IIf([Age] Between 0 And 3,"0-3",IIf([Age] Between 4 And 12,"4-12",IIf([Age] Between 13 And 18,"13-18","19+")))) AS AgeGroupCount[/size][/font]

[font=Tahoma][size=3]FROM Age[/size][/font]

[font=Tahoma][size=3]GROUP BY Age.Age, IIf([Age] Between 0 And 3,"0-3",IIf([Age] Between 4 And 12,"4-12",IIf([Age] Between 13 And 18,"13-18","19+")))[/size][/font]

[font=Tahoma][size=3]ORDER BY Age.Age;[/size][/font]

[font=Tahoma][size=3] [/size][/font]

[font=Tahoma][size=3] [/size][/font]

[font=Tahoma][size=3] [/size][/font]

[font=Tahoma][size=3]Crosstab Query[/size][/font]

[font=Tahoma][size=3]__________________________________________________ _________________[/size][/font]

[font=Tahoma][size=3]TRANSFORM Sum(AgeGroup.AgeGroupCount) AS SumOfAgeGroupCount[/size][/font]

[font=Tahoma][size=3]SELECT AgeGroup.AgeGroup[/size][/font]

[font=Tahoma][size=3]FROM AgeGroup[/size][/font]

[font=Tahoma][size=3]GROUP BY AgeGroup.AgeGroup[/size][/font]

[font=Tahoma][size=3]PIVOT AgeGroup.AgeGroup;[/size][/font]
May 22 '07 #2

P: 10
Thanks for the reply! I will try it.

Jayme

Yes, Access can do this (see below). I did this in two steps. For step #1, I created a query to setup the groupings and place each raw data item in the applicable group. The in step #2, I used the above query as the source for a crosstab query to summarize the counts by group/

[font=Tahoma][size=3]Source (Base) Query[/size][/font]

[font=Tahoma][size=3]__________________________________________________ ______________________[/size][/font]

[font=Tahoma][size=3]SELECT Age.Age, IIf([Age] Between 0 And 3,"0-3",IIf([Age] Between 4 And 12,"4-12",IIf([Age] Between 13 And 18,"13-18","19+"))) AS AgeGroup, Count(IIf([Age] Between 0 And 3,"0-3",IIf([Age] Between 4 And 12,"4-12",IIf([Age] Between 13 And 18,"13-18","19+")))) AS AgeGroupCount[/size][/font]

[font=Tahoma][size=3]FROM Age[/size][/font]

[font=Tahoma][size=3]GROUP BY Age.Age, IIf([Age] Between 0 And 3,"0-3",IIf([Age] Between 4 And 12,"4-12",IIf([Age] Between 13 And 18,"13-18","19+")))[/size][/font]

[font=Tahoma][size=3]ORDER BY Age.Age;[/size][/font]

[font=Tahoma][size=3] [/size][/font]

[font=Tahoma][size=3] [/size][/font]

[font=Tahoma][size=3] [/size][/font]

[font=Tahoma][size=3]Crosstab Query[/size][/font]

[font=Tahoma][size=3]__________________________________________________ _________________[/size][/font]

[font=Tahoma][size=3]TRANSFORM Sum(AgeGroup.AgeGroupCount) AS SumOfAgeGroupCount[/size][/font]

[font=Tahoma][size=3]SELECT AgeGroup.AgeGroup[/size][/font]

[font=Tahoma][size=3]FROM AgeGroup[/size][/font]

[font=Tahoma][size=3]GROUP BY AgeGroup.AgeGroup[/size][/font]

[font=Tahoma][size=3]PIVOT AgeGroup.AgeGroup;[/size][/font]
May 22 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.