Solved

Access Query: flip from vertical to horizontal for a report

Posted on 2008-11-03
6
1,162 Views
Last Modified: 2013-11-28
Access 2003
Query, Report

Hello,

I'm trying to take information from a query and flip it from vertical to horizontal in a report. I start with this query:

StaffingGroup          PayGrade          CountOfPayGrade
Clerical                    1                       1
Clerical                    2                       1
Clerical                    3                       1
Sales                       1                       2
Sales                       2                      11
Management           1                      2



And then want to represent it in a report like this:

StaffingGroup      PayGrade 1      PayGrade 2      PayGrade 3
Clerical                1                      1                      1
Sales                   2                      11                    0
Management       2                      0                      0


My first thought is to rotate the information in a query first and then pull from that query to make the report. However, I can't figure out how to rotate the query to show the information in a horizontal format.  Thanks.
0
Comment
Question by:BradleyOnTheRoad
  • 2
  • 2
  • 2
6 Comments
 
LVL 17

Expert Comment

by:aflockhart
ID: 22867930
Set up a Crosstab Query from your data.

Staffing group will be a row heading
Pay Grade wil be a column heading
ANy field that always has a value (Paygrade could be used) is the data value.

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22873779
BradleyOnTheRoad,

I tried this as a crosstab with both fields, and neither relly gave me what you are loking for.

It it possible to see the Raw data *before* you got: "CountOfPayGrade"
?

JeffCoachman
0
 

Author Comment

by:BradleyOnTheRoad
ID: 22876460
 boag 2000
                 <!--[if gte mso 9]>   Normal  0      false  false  false                     MicrosoftInternetExplorer4 <![endif]--><!--[if gte mso 9]>  <![endif]--><!--[if gte mso 10]><![endif]-->StaffingGroup         PayGrade        
Clerical                   1                      
Clerical                   2                      
Clerical                   3                      
Sales                       1                      
Sales                       1                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Management           1                      
Management           1                      
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:BradleyOnTheRoad
ID: 22876476
Let's try that again.

StaffingGroup         PayGrade        
Clerical                   1                      
Clerical                   2                      
Clerical                   3                      
Sales                       1                      
Sales                       1                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Sales                       2                      
Management           1                      
Management           1                      
0
 
LVL 17

Accepted Solution

by:
aflockhart earned 250 total points
ID: 22876562
Did you try it with a crosstab query based on your original data ?


The SQL that it generates will be something like this:  (change to include your table/field names)

TRANSFORM Count(Staff.ID) AS CountOfID
SELECT Staff.StaffingGroup, Count(Staff.ID) AS [Total Of ID]
FROM Staff
GROUP BY Staff.StaffingGroup
PIVOT Staff.PayGrade;


or if you don't want overall totals on each row:


TRANSFORM Count(Staff.ID) AS CountOfID
SELECT Staff.StaffingGroup
FROM Staff
GROUP BY Staff.StaffingGroup
PIVOT Staff.PayGrade;



0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 250 total points
ID: 22882686
BradleyOnTheRoad,

Thanks,
As you can see, the *raw* data can easily be summarized using one of aflockhart's suggestions.

The first data structure you posted was already summarized, making this difficult.
;-)

JeffCoachman
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now