Solved

Access Query: flip from vertical to horizontal for a report

Posted on 2008-11-03
6
1,163 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

803 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