cross tab query (1 Viewer)

kobiashi

Registered User.
Local time
Today, 22:13
Joined
May 11, 2018
Messages
258
hi

i am trying to create a cross tab query but i cant seem to display the info how i want it.

i have two tables

table_wheelcavities table 1
wheelcavities_ID
vehicle_IDFK
DateAdded
Mileage
PrintName
MaximoNo

table_wheelCavities_M2M table 2
wheelcavities_M2M_ID
wheelcavities_IDFK
DateAdded
Wheel_IDFK
WorkType_IDFK
PositionOfOilInjector
length
width
depth
height
thickness
rollover


table_wheelcavities is left join to table_wheelcavities_M2M

so from table 2 user chooses worktype_IDFK, options are flats,cavities,flange heights, flange thickness, real flange thickness, rollover,
and adds dimension, not all the fields are filled in, so for example, if the user chooses flats, he only uses length, width and depth.


so in the crosstab query i want to be able to display the dimensions, with worktype as the column headers and the dimension type as the row header, ive tried to use expr as the row headers and the dimensions as values, but i just cant get it to work.
 

June7

AWF VIP
Local time
Today, 13:13
Joined
Mar 9, 2014
Messages
5,470
You show fields for dimensions. You want to switch so the dimensions are rows? Post example of raw data and desired output.
 

isladogs

MVP / VIP
Local time
Today, 22:13
Joined
Jan 14, 2017
Messages
18,219
Just add your length, width, height fields as additional row headings in the query design window. Although the wizard only allows three row headings, the designer has no such restriction.
 

kobiashi

Registered User.
Local time
Today, 22:13
Joined
May 11, 2018
Messages
258
You show fields for dimensions. You want to switch so the dimensions are rows? Post example of raw data and desired output.

ss1.png is the raw data from the query

ss2.png is the desired output, so the row headers are the dimension types, ie length, height, width
and the column headers are the work types, the values are the dimension values
 

Attachments

  • ss1.PNG
    ss1.PNG
    10.2 KB · Views: 41
  • ss2.PNG
    ss2.PNG
    4.6 KB · Views: 48

kobiashi

Registered User.
Local time
Today, 22:13
Joined
May 11, 2018
Messages
258
Just add your length, width, height fields as additional row headings in the query design window. Although the wizard only allows three row headings, the designer has no such restriction.


how can i aggregate the workype so i can use them as column headers?
 

June7

AWF VIP
Local time
Today, 13:13
Joined
Mar 9, 2014
Messages
5,470
That doesn't look like raw data, looks like a CROSSTAB query.
 

kobiashi

Registered User.
Local time
Today, 22:13
Joined
May 11, 2018
Messages
258
That doesn't look like raw data, looks like a CROSSTAB query.

when you say raw data, what do you want to see? just the data, or table with headers, the screen shot is just a select query, thats been grouped, and ive sum totaled the dimensions, length, width, depth, height, thickness, rollver
 

June7

AWF VIP
Local time
Today, 13:13
Joined
Mar 9, 2014
Messages
5,470
So the dimensions are already in separate fields in the table? You want to switch the dimensions to be rows? That would involve UNION query to reorganize the fields. Then a CROSSTAB to pivot on the Worktype.

Example of UNION:

SELECT wheelcavities_M2M_ID, WTDesc, "Length" AS Dimension, Length AS Data FROM Table1 LEFT JOIN WorkTypes ON Table1.WorkType_IDFK = WorkTypes.WorkTypeID
UNION SELECT wheelcavities_M2M_ID, WTDesc, "Width", Width FROM Table1 LEFT JOIN WorkTypes ON Table1.WorkType_IDFK = WorkTypes.WorkTypeID;

Then the Crosstab:

TRANSFORM Sum(Data) AS SumOfData
SELECT Dimension
FROM Query1
GROUP BY Dimension
PIVOT WTDesc;
 
Last edited:

kobiashi

Registered User.
Local time
Today, 22:13
Joined
May 11, 2018
Messages
258
thaks for the reply

all i really want to do is display the values under a column and row header, it really doesnt matter which is which, i need to be able to split the data into columns, and rows, the criteria is per dimension, lets say length and the worktype is cavities and flats, i need to be able to display that data in a table, so the column header could be length and the row header would be cavity and flats
 

June7

AWF VIP
Local time
Today, 13:13
Joined
Mar 9, 2014
Messages
5,470
Then you already have dimensions as column headers and worktypes as row headers. If you want the worktype description and not the ID, then build a query that joins tables so the description can be retrieved.

That does not involve CROSSTAB, just JOIN.
 

Users who are viewing this thread

Top Bottom