Solved

Crosstab Query to Summarize Data Horizontally

Posted on 2014-12-09
27
182 Views
Last Modified: 2014-12-10
This is a follow up to the question at the link below.

http://www.experts-exchange.com/Database/MS_Access/Q_28562271.html

I have my schema set up as stated in the above solution using the hybrid approach - one central table for the shared attributes and then EAV tables to describe the non-shared attributes.  In some cases, for certain forms and reports, I need to be able to display data as column headings that are displayed as row headings in this schema.  Instead of having the following information displayed for one property for example:

Type : Residential
Owner : John Smith
Year Built : 2005
Lot Size : 1 acre
Sewer :  Septic
Water : Well

I need to be able to display this data summarized for multiple properties like this :


                   Type                   :  Owner                    :  Year Built          :    Lot size    :    Sewer    :      Water
Property 1   Residential             John Smith                2005                     1 acre           Septic           Well
Property 2   Commercial            Bob Thomas             1987                     5 acres         Public           Public
Property 3   Residential             Mark Jones                2011                    .38 acre        Public           Well


I thought this was what a crosstab query was for but I can't get it to display the actual data elements.  So far it will only let me count, or sum the elements.  I want to actually display them.
0
Comment
Question by:yoducati
  • 17
  • 8
  • 2
27 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40489126
a copy of your tables/db will help..
0
 

Author Comment

by:yoducati
ID: 40489193
This is the best I can do.  I can't post the full db. But these are the essential tables and query.  I need the qryTest to display the information as I mentioned above.
Sample.accdb
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40489230
sorry,  i can't open your A2010 version db.
can you create a new db and just import the tables, query to the newly created db,
save db as Access 2003 database
then upload
0
 

Author Comment

by:yoducati
ID: 40489236
It doesnt give me the option to save it as an older version.
0
 

Author Comment

by:yoducati
ID: 40489256
Rather it prohibits me from saving in an older version.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40489949
Based on this specific question, ...are you quite sure the "Hybrid" approach was best?
What you are asking for here now seems to need another design methodology?

I am sure an expert here can "twist" the data to give you what you are after here, ...
...but sometimes it is more efficient to reconsider you design approach... (so hat this is not needed...

Lets see if either of the experts form your previous Q chimes in with more in depth insight...
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40489956
If it were me, ...I would have separated the Vehicles from the Properties,...
But again, lets see if Jim or Pat Chimes in on this...
(I may not have a full grasp of your requirements...)
0
 

Author Comment

by:yoducati
ID: 40489963
Nope not sure.  Working it all out still.  There are many more types than just vehicles and properties.  Those were just examples.  I went with the hybrid approach because it accomplished all I needed it to do very nicely when I though a crosstab query would let me reorganize for views/reporting.  Now I am considering a main table, with many other individual tables for each asset type.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40490084
see the crosstab query "qryTest_Crosstab"
Sample.accdb
0
 

Author Comment

by:yoducati
ID: 40491239
Im not able to open it.  I get a pop up window with random characters in it when I click the link.  This happend to me before but I can't remember what the issue was.  Maybe the version?  Or it might need to be zipped?
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40491249
do a right click and select save link as
or use another browser (chrome)
0
 

Author Comment

by:yoducati
ID: 40491254
I dont have access to another browser.  Save as options aren't available.  Let me go back through my other questions and Ill see if I can figure out what happened last time.
0
 

Author Comment

by:yoducati
ID: 40491272
The other ones had to be zipped in order for me to open them.  I think its a combination of the access version, and maybe my browser.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:yoducati
ID: 40491523
For what its worth I can't even open the sample database that I posted above.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40491607
export the 4 tables to excel (right click on table > export )

place all excel file in a folder, zipped the folder and upload
0
 

Author Comment

by:yoducati
ID: 40491681
It wont let me upload them
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40491722
upload all the excel files
0
 

Author Comment

by:yoducati
ID: 40491735
0
 

Author Comment

by:yoducati
ID: 40491737
0
 

Author Comment

by:yoducati
ID: 40491738
0
 

Author Comment

by:yoducati
ID: 40491739
0
 

Author Comment

by:yoducati
ID: 40491744
It wouldnt let me do that before either.  I think its mostly my browser causing the issue.  I have no control over that though.  Its supposed to get updated soon.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40491872
post the SQL statement of your query "qryTest"
0
 

Author Comment

by:yoducati
ID: 40491886
SELECT tblAssets.AssetID, tblAttributes.AttributeDescription, tblAssetAttributes.PValue
FROM tblAssetTypes INNER JOIN (tblAttributes INNER JOIN (tblAssets INNER JOIN tblAssetAttributes ON tblAssets.AssetID = tblAssetAttributes.AssetID) ON tblAttributes.AttributeID = tblAssetAttributes.[Attribute ID]) ON tblAssetTypes.TypeID = tblAttributes.TypeID;
0
 

Author Comment

by:yoducati
ID: 40491896
Here is a pdf of the query results as is.  I need the asset ID as a row heading and they should be grouped by asset ID.  Each attribute description should be a column heading.  The PValue should be the data displayed for each asset ID.
qryTest.pdf
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 40492011
first create this query

SELECT tblAssets.AssetID, tblAttributes.AttributeDescription, tblAssetAttributes.PValue, tblAssetTypes.TypeDescription
FROM tblAssetTypes INNER JOIN (tblAttributes INNER JOIN (tblAssets INNER JOIN tblAssetAttributes ON tblAssets.AssetID = tblAssetAttributes.AssetID) ON tblAttributes.AttributeID = tblAssetAttributes.[Attribute ID]) ON tblAssetTypes.TypeID = tblAttributes.TypeID;

save as qryTest

then create this query

TRANSFORM First(qryTest.[PValue]) AS FirstOfPValue
SELECT qryTest.[AssetID], qryTest.[TypeDescription]
FROM qryTest
GROUP BY qryTest.[AssetID], qryTest.[TypeDescription]
PIVOT qryTest.[AttributeDescription];
0
 

Author Closing Comment

by:yoducati
ID: 40492115
Thanks for the help. This is exactly what I was trying to do but I didn't realize I needed two queries to do it.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Read about achieving the basic levels of HRIS security in the workplace.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now