spliting 1 long table into many tables based on Months.

PaulJL

New Member
Joined
Oct 9, 2002
Messages
48
I have a table with two columns, Customer code and Date of invoice sent. (approximately 3/4 million Rows), I need to be able to see the pattern of when the customer code was invoiced. ie every month, every quarter, every half year and so on.

I have used the distinct command to create a unique list of customer codes, now i need to create a table which shows the customer code along with a True/false entry for each month (with each month in a different column). (approximately 2 and a half years). I have done something similar in excel by downloading seperate months and storing them as worksheets and then using a vlookup to reference these worksheets but only for small sections of the file. Is what i am asking possible in Access without too much difficulty.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Is what i am asking possible in Access without too much difficulty.

I think so. You'll have to create 2 queries, but it won't be that difficult.

Ok, first query:

Select your CustomerCode and your Date field, then add a field like this (just type it in the top line):

YearMon: Year([fldDate]) & Format(Month([fldDate]),"00"

Then click on the "Totals" button on the toolbar (the Sigma) -- or go to View-Totals.

Group by the CustomerCode and the "YearMon" fields, and COUNT the Date field.

Run the query to see if it works and then save it (I called mine qry020403a - I'm telling you this b/c I'm going to paste my SQL below).

Now, go to the query tab and create a new query using the Crosstab wizard. For the row headings, select the CustomerCode. For the column headings, select YearMon, and for the calculated column, select the Count field (using Acc2000, I unchecked the "Yes, Include Sums" checkbox).

That should do it. You'll get blanks for any month that does not have a date for that particular customer. Here's my 2 queries - my fields were named fldCustCode and fldDate, and I didn't change any of the field names that Access automatically assigns (such as "CountOffldDate"). My table name was tbl020403.

Query1 (again, I saved this query as qry020403a):

SELECT tbl020403.fldCustCode, Year([fldDate]) & Format(Month([fldDate]),"00") AS YearMon, Count(tbl020403.fldDate) AS CountOffldDate
FROM tbl020403
GROUP BY tbl020403.fldCustCode, Year([fldDate]) & Format(Month([fldDate]),"00");

Query2 (crosstab):

TRANSFORM Sum(qry020403a.CountOffldDate) AS SumOfCountOffldDate
SELECT qry020403a.fldCustCode
FROM qry020403a
GROUP BY qry020403a.fldCustCode
PIVOT qry020403a.YearMon;

HTH,

Russell
 
Upvote 0
Paul, Russell,

Unless I'm missing something, I think you can go right to the crosstab query (leastwise it worked for me :) ). Here's the SQL for it:

TRANSFORM Count(tblCust.InvDate) AS CountOfInvDate
SELECT tblCust.CustID
FROM tblCust
GROUP BY tblCust.CustID
PIVOT DateValue(Month([InvDate]) & "/1/" & Year([InvDate]));

The "datevalue" bit just changes the "month," represented by the first of the month, back into a format that is recognized as a date.


hth
 
Upvote 0

Forum statistics

Threads
1,221,508
Messages
6,160,222
Members
451,631
Latest member
coffiajoseph

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top