Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I sum data by Month/Year using a crosstab query?

Status
Not open for further replies.

jose3106

Technical User
Aug 25, 2006
3
US
I have a dataset that spans multiple years. I want to create a crosstab query that sums the data by Month/Year. When I run the query, the results are based on the actual date resulting in a crosstab query that has thousands of columns. Here is the desired output:
12/05 1/06 2/06
Company X $252 $500 $100

Thanks!
 
How far have you got so far? Can you post your SQL?

Also, what is the structure of the underlying data in your database?

John
 
Below is the SQL code. It is currently formatted to sum the data by month.

TRANSFORM Sum(Bookings.[Booking Amount]) AS [SumOfBooking Amount]
SELECT Bookings.[National Account], Sum(Bookings.[Booking Amount]) AS [Total Of Booking Amount]
FROM Bookings
GROUP BY Bookings.[National Account]
PIVOT Format([Contract Commence Date],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
 
Try something like:

TRANSFORM Sum(Bookings.[Booking Amount]) AS [SumOfBooking Amount]
SELECT Bookings.[National Account], Sum(Bookings.[Booking Amount]) AS [Total Of Booking Amount]
FROM Bookings
GROUP BY Bookings.[National Account]
PIVOT Format([Contract Commence Date],"yyyy/mm");

Its not quite what you wanted, but fairly close.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top