Solved

Crosstab or Pivot Table without numbers

Posted on 2014-04-25
6
527 Views
Last Modified: 2014-04-26
I'm trying to create a crosstab query in MS Access that would show only character values instead of numbers as values.  The query is supposed to show a rating (e.g. H, M or L) as values for each risk (rows) and departments (columns).  The table driving this crosstab query doesn't have duplicate department/risk combination.  I haven't been able to do this with pivot tables/cross tab query because it only seem to allow numbers as values.  Any ideas?
0
Comment
Question by:eklin
  • 3
  • 2
6 Comments
 
LVL 34

Expert Comment

by:PatHartman
Comment Utility
Convert the values to strings in the base query.  Then in the crosstab choose min/max/first/last to select the value to display.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
If you only have a single record for each combination of row/column headers, then you should be able to use "first" or "last" as the aggregation method for the cells that go into the crosstab.

If you have multiple values and you need to perform some preliminary operation to determine the rating across multiple records before you create the crosstab.

It would be much easier to address your question if you could provide some sample data and how you want your output to look, with an explanation of how each cell in the crosstab was calculated.
0
 

Author Comment

by:eklin
Comment Utility
Pat - what I'm trying to do is avoid substituting the character values to numbers and then back.  It's too messy.  I'm trying to do this in one query.

Dale - thanks for the tip.  I've attached the sample data and desired results in the attached spreadsheet.  I'm hoping there is a way to do this through a query instead of using VBA.  We had a consultant code this in VBA before.  She converted the characters (high/medium/low) to numbers and then back to perform the crosstab but performance wise it is taking over 8hrs to process 7,500 rows of records, where I can do this manually with Excel in less than 1 hr.  In Excel, you can choose 2 values for the columns and it works nicely because the columns can be displayed in the desired order if you choose that field first.
Sample-Crosstab.xlsx
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
Comment Utility
I can't imagine why this is taking over 8 hours.  Even an inefficient loop with multiple DLookup()s shouldn't take that long.

This is what the query should look like.  I chose "First" as the Transform operator but if the data is unique as you say it is, then First/Last/Min/Max will all produce the same result as I mentioned in my first post.  

Requiring that the columns be in an order other than alphabetical means that you need an In() clause.  The danger with that is that your pivot is now constrained to ONLY the values listed in the In() clause.  If you add a new department, it will be ignored.  The up side of having the In() clause is that you always get a fixed set of columns which would make reporting easier.

TRANSFORM First(Table2.[Risk]) AS FirstOfRisk
SELECT Table2.[Risk Category]
FROM Table2
GROUP BY Table2.[Risk Category]
PIVOT Table2.[Department] In ("Sales","Accounting","IT","Administrative");

QBE view
0
 

Author Comment

by:eklin
Comment Utility
Pat,  this is just what I needed.  Thanks!
0
 
LVL 34

Expert Comment

by:PatHartman
Comment Utility
You're welcome.

PS - I used the wizard to build it.  Access has many useful wizards and this is one of them.  After I built the query, I switched to QBE view and removed the "totals" column since for a crosstab like this one it doesn't make sense given that there is nothing in the row to sum.  Although the wizard limits you to three columns as "Row Heading", you can modify the query after the wizard finishes to add more if you need them.  In your case we only needed one but I mention it because I want to make it clear that once the wizard is finished, the query is yours to modify.
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

763 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

6 Experts available now in Live!

Get 1:1 Help Now