Solved

Access Transform CrossTab Query with Default Column Names not Row Names

Posted on 2014-12-07
4
169 Views
Last Modified: 2014-12-08
I have a query that I would like the results to be in columns not rows, but I do not want the column names to be the row result names.

TRANSFORM First(part_id) AS FirstOfPartID
SELECT part_id, id
FROM qryqfitraceonhand
GROUP by PART_ID, ID
PIVOT part_id


Here is the query results and the how I would like the table to look.  I spent a couple hours looking for answers and I think I may need code for this.

I can modify the data in excel as well, if that is easier, but I do not know how to do that either.

TIA,

Faunna Bartlett
ExpertsExchangeCrossTabQuery.JPG
0
Comment
Question by:cadencedba
  • 2
4 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40486448
I would do this as two queries, just to make the coding easier:

Query 1 (which I've called qryqfitraceonhand2):

SELECT A.Part_ID, A.ID, A.TraceQty, A.Qty_on_Hand, Count(B.ID) AS CountOfID
FROM qryqfitraceonhand AS A INNER JOIN qryqfitraceonhand AS B ON (A.Part_ID = B.Part_ID) AND (A.ID >= B.ID)
GROUP BY A.Part_ID, A.ID, A.TraceQty, A.Qty_on_Hand;

Open in new window


Query 2:

SELECT A.Part_ID, A.ID AS Trace1, A.TraceQty AS Trace1_Qty, B.ID AS Trace2, B.TraceQty AS Trace2_Qty, C.ID AS Trace3, C.TraceQty AS Trace3_Qty, D.ID AS Trace4, D.TraceQty AS Trace4_Qty
FROM (((SELECT * FROM qryqfitraceonhand2 WHERE CountOfID = 1) AS A LEFT JOIN (SELECT * FROM qryqfitraceonhand2 WHERE CountOfID = 2)  AS B ON A.Part_ID = B.Part_ID) LEFT JOIN (SELECT * FROM qryqfitraceonhand2 WHERE CountOfID = 3)  AS C ON A.Part_ID = C.Part_ID) LEFT JOIN (SELECT * FROM qryqfitraceonhand2 WHERE CountOfID = 4)  AS D ON A.Part_ID = D.Part_ID;

Open in new window

0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40486449
It gives a slightly different answer, because there are some typos? in your data - but it gives the right answer based on your data.
0
 
LVL 35

Expert Comment

by:PatHartman
ID: 40487124
You can do this with a crosstab but you need to use two of them because a crosstab can only pivot one column at a time and then join the 2 crosstabs.   Generating dummy names for the column headers will be required but you can use the "First" option to select the values.
0
 

Author Comment

by:cadencedba
ID: 40487967
Thank you!  I used Phillips solutions.  I had done this a year ago, but forgot what I had done to get there.  I also added more columns.
0

Featured Post

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.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

773 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