Solved

Crosstab or Pivot Table without numbers

Posted on 2014-04-25
6
530 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
ID: 40024154
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)
ID: 40024295
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
ID: 40024554
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
ID: 40024677
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
ID: 40024936
Pat,  this is just what I needed.  Thanks!
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 40024964
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unrecognized Database Format 8 93
linked subforms are yielding error:  ... (800110108) 3 16
access 7 25
Running Total in Access 4 17
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

895 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

14 Experts available now in Live!

Get 1:1 Help Now