Solved

Access Transform CrossTab Query with Default Column Names not Row Names

Posted on 2014-12-07
4
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 38

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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 …

626 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