Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Crosstab or Pivot Table without numbers

Posted on 2014-04-25
6
Medium Priority
?
561 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 40

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 49

Expert Comment

by:Dale Fye
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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 40

Accepted Solution

by:
PatHartman earned 2000 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 40

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

876 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