Avatar of snooflehammer
snooflehammer
Flag for Australia asked on

Acccess CrossTab Query?

Not sure if this should be a crosstab query or not, but I can't make it work.

I have extracted some data from a table which contains two values. One is the source of the business, we'll call that field SOURCE, the other is the date the enquiry was taken. We'll call that DATE.

There are around 17 different sources of business.

The object of the exercise is to create a table where the columns are the SOURCE value and the rows are the DATE value.

Each row of DATE information has to be collated by year, so the first row is all leads taken in 2015 by source of business, the next row is 2014, etc..

How to create such a query?
Microsoft Access

Avatar of undefined
Last Comment
snooflehammer

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dale Fye

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
snooflehammer

ASKER
Outstanding answer. Thank you. Next time you're in Eumundi I'll buy you a beer :)
snooflehammer

ASKER
This guy is the man
snooflehammer

ASKER
Just FYI, I had a separate table with the sources and was just using the ID in the main table, so my SQL statement looked like this:

TRANSFORM Count(tblSources.Source) AS CountOfSource
SELECT Year([DateTaken]) AS [Year]
FROM BiilsSourceOfLeads INNER JOIN tblSources ON BiilsSourceOfLeads.Source = tblSources.SourceID
GROUP BY Year([DateTaken])
ORDER BY Year([DateTaken]) DESC
PIVOT tblSources.Source;

Thanks again
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Dale Fye

Glad i could help
snooflehammer

ASKER
Now the client wants to get the results by financial year (July 1 - June 30) instead of calendar year. I'll post that as a new question and notify you when I do so.
Dale Fye

It is just a matter of transforming the DateTaken field by adding or subtracting the appropriate number of months using the DateAdd( ) function.

If for example the financial year of 2015 actually began on 1 Oct, 2014, then you would do something like:

TRANSFORM Count(tblSources.Source) AS CountOfSource
SELECT Year(DateAdd("m", 3, [DateTaken])) AS [Year]
FROM BiilsSourceOfLeads
INNER JOIN tblSources ON BiilsSourceOfLeads.Source = tblSources.SourceID
GROUP BY Year(DateAdd("m", 3, [DateTaken]))
ORDER BY Year(DateAdd("m", 3, [DateTaken])) DESC
PIVOT tblSources.Source;
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
snooflehammer

ASKER
Ah! Sweet. Thank you