Solved

MS Access Crosstab Query -- column headings that display year and month across multiple years

Posted on 2009-04-13
9
1,288 Views
Last Modified: 2012-06-27
I'd like to create a multi-year crosstab query that looks like this:

                                     2008 Nov     2008 Dec     2009 Jan    2009 Feb
            Group 1
            Group 2
            Group 3

I know how to do this for "quarters" (e.g., 2008 Q2), but I can't seem to find a way to do it for "months."
0
Comment
Question by:WallyTee
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 24129799
Continuing from the previous question you submitted, try this:
          PIVOT Format(a.RegisteredDate,"yyyymmm");
0
 

Author Comment

by:WallyTee
ID: 24129869
Hi puppydogbuddy:   Thanks for the super-quick response!  

The Years and Months appeared OK, but they are in alphabetical and not chronological order, left to right.  I'd love to get them in chronological order.  Any ideas on this?
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 24129948
No points for this, please :)

WallyTee said:
>>I'd love to get them in chronological order.  Any ideas on this?

PIVOT Format(a.RegisteredDate,"yyyy-mm")
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 24130013
Try this-change the two lines as indicated:
Year(Format(a.RegisteredDate, "yyyymmm")>2005      '<<<<<<<<
GROUP BY a.Product
PIVOT (a.RegisteredDate);                   '<<<<<<<<<<
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 24130020
oops, left out a right parens:

Year(Format(a.RegisteredDate, "yyyymmm"))>2005      
0
 
LVL 44

Expert Comment

by:GRayL
ID: 24130057
Pivot Year(Format(a.RegisteredDate" "yyyy mmm") in ("Jan","Feb","Mar",.....,"Nov","Dec")
0
 
LVL 44

Expert Comment

by:GRayL
ID: 24130061
Correction:

Pivot Format(a.RegisteredDate, "yyyy mmm") in ("Jan","Feb","Mar",.....,"Nov","Dec")
0
 
LVL 44

Expert Comment

by:GRayL
ID: 24130083
If you can accept 20008 11, 2008 12, 2009 01, etc>

PIVOT Format(a.RegisteredDate,"yyyy mm")


0
 

Author Closing Comment

by:WallyTee
ID: 31569497
Good solution. It uses numbers to represent months, but that's fine.  They appear in the correct order.  Many thanks.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ORDER BY 7 37
SQL Get Store Procedure Column Name As Row 5 39
Get data from two MySQL tables 6 21
Delete old Sharepoint backups 2 14
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

740 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