Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access Transform CrossTab Query with Default Column Names not Row Names

Posted on 2014-12-07
4
Medium Priority
?
191 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 2000 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 40

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

971 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