|
Question : Crosstab Query across multiple fiscal (not calendar) years by month
|
|
I am attempting to create a crosstab query where I need to accomplish two objectives:
1. Match the report to the fiscal year that begins Dec 1 and end Nov 30 2. String two fiscal years worth of data by month across the columns, beginning with Dec 1, 2004 and ending with Nov 30, 2006
The table (TBL_TRANS) columns used and sample data are: TRANS_DATE PAYEE TRANS_AMT 06/02/2006 ABC 1000.00 05/06/2006 ABC 2000.00 05/10/2005 CDE 3000.00
Using the wizard, I get the following code that generates the crosstab within the year:
TRANSFORM Sum(TBL_TRANS.TRANS_AMT) AS SumOfTRANS_AMT SELECT TBL_TRANS.PAYEE, Sum(TBL_TRANS.TRANS_AMT) AS [Total Of TRANS_AMT] FROM TBL_TRANS GROUP BY TBL_TRANS.PAYEE PIVOT Format([TRANS_DATE],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
What I want for the end result of the query is:
PAYEE Dec 04 Jan 05 Feb 05 Mar 05 etc... Nov 05 Total FY 05 Dec 05 etc...Nov 06 Total FY 06
Thanks, Tom
|
|
Answer : Crosstab Query across multiple fiscal (not calendar) years by month
|
|
Sorry, my mistake:
TRANSFORM Sum(TBL_TRANS.TRANS_AMT) AS SumOfTRANS_AMT SELECT TBL_TRANS.PAYEE, Year(TRANS_DATE) + Iif(TRANS_DATEYear(TRANS_DATE,12,1),0,1) AS FY, Sum(TBL_TRANS.TRANS_AMT) AS [Total Of TRANS_AMT] FROM TBL_TRANS Where TRANS_DATE BETWEEN #2004-12-01# and #2006-11-30# GROUP BY TBL_TRANS.PAYEE, Year(TRANS_DATE) + Iif(TRANS_DATE,(Year(TRANS_DATE,12,1) PIVOT Format([TRANS_DATE],"yymm");
|
|
|
|