Another **** Year to Date Report Question

G

garylm

I need to create a YTD Report in the following format:

CurrMonth PrevMonth CurrYear
PrevYear
Customer1 2 1 7
5
Customer2 6 19 15
12 etc...

CurrMonth: This month
PrevMonth: Same month last year
CurrYear: This year up to and through CurrMonth
PrevYear: Last year up to and including PrevMonth

I have a query that gathers the records I need from a single table but for
the life of me I can't retreive the sum of quantities I need for the pivot
action. Is there a way to create the report without a Query or how can I
extract the numbers from my query and total them on the report? Please help!!
! The hair I haven't pulled out is completely gray.
 
J

John Spencer

SELECT Customer

, SUM(IIF(SomeDate Between DateSerial(Year(Date()),Month(Date()),1) AND
Date(),Amount, Null)) as CurrMonth

,SUM(IIF(SomeDate Between DateSerial(Year(Date())-1,Month(Date()),1) AND
DateSerial(Year(Date())-1,Month(Date(),Day(Date()),Amount, Null)) as PriorMonth

,SUM(IIF(SomeDate Between DateSerial(Year(Date()),1,1) AND Date()) as CurrYear

,SUM(IIF(SomeDate Between DateSerial(Year(Date())-1,1,1) AND
DateSerial(Year(Date())-1,Month(Date(), Day(Date()),Amount, Null)) as PriorYear

FROM SomeTable
WHERE SomeDate Between DateSerial(Year(Date())-1,1,1) and Date()
GROUP BY Customer

If you want the end of the month instead of the current date, you will have to
adjust the criteria used.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
G

garylm via AccessMonster.com

John: I do well appreciate your efforts on my behest, However, I pasted the
formuila below into a query and only the CurrMonth portion will return a
result. When I add the PriorMonth portion, it gives me an error "Syntax
Error (missing operator)". I think this is do to a conflict on the multiple
date groups. Am I supposed to create 4 separate queries and the 1 more where
I join all the information for the report. Ick!!!

Gary(dash)Mitchell(at)live(dot)com

John said:
SELECT Customer

, SUM(IIF(SomeDate Between DateSerial(Year(Date()),Month(Date()),1) AND
Date(),Amount, Null)) as CurrMonth

,SUM(IIF(SomeDate Between DateSerial(Year(Date())-1,Month(Date()),1) AND
DateSerial(Year(Date())-1,Month(Date(),Day(Date()),Amount, Null)) as PriorMonth

,SUM(IIF(SomeDate Between DateSerial(Year(Date()),1,1) AND Date()) as CurrYear

,SUM(IIF(SomeDate Between DateSerial(Year(Date())-1,1,1) AND
DateSerial(Year(Date())-1,Month(Date(), Day(Date()),Amount, Null)) as PriorYear

FROM SomeTable
WHERE SomeDate Between DateSerial(Year(Date())-1,1,1) and Date()
GROUP BY Customer

If you want the end of the month instead of the current date, you will have to
adjust the criteria used.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
I need to create a YTD Report in the following format:
[quoted text clipped - 15 lines]
extract the numbers from my query and total them on the report? Please help!!
! The hair I haven't pulled out is completely gray.
 
J

John Spencer

No, the problem is that there are syntax errors in the query. By the way that
is ONE query and should be treated as one query.

I missed a closing parenthesis in the DateSerial function. I have
Month(Date(), and I should have Month(Date()), and now that I examine this a
little closed I note some other problems with those pesky parentheses.
Hopefully all is not correct

Also, I was not sure if you wanted the same time frame for the current month
and prior year month. For example, 1 March to 21 March in both 2009 and 2010.
I can think of one occasion where the result could be off. If the current
date was Feb 29th you will get data for Feb 1 to Mar 1 for the prior year's
month. If that is important, you will need to rewrite the criteria.


SELECT [Customer]

, SUM(IIF([SomeDate] Between DateSerial(Year(Date()),Month(Date()),1) AND
Date(),[Amount], Null)) as CurrMonth

,SUM(IIF([SomeDate] Between DateSerial(Year(Date())-1,Month(Date()),1) AND
DateSerial(Year(Date())-1,Month(Date()),Day(Date()),[Amount], Null)) as PriorMonth

,SUM(IIF([SomeDate] Between DateSerial(Year(Date()),1,1) AND
Date(),[Amount],Null)) as CurrYear

,SUM(IIF([SomeDate] Between DateSerial(Year(Date())-1,1,1) AND
DateSerial(Year(Date())-1,Month(Date()), Day(Date())),[Amount], Null)) as
PriorYear

FROM [SomeTable]
WHERE [SomeDate] Between DateSerial(Year(Date())-1,1,1) and Date()
GROUP BY Customer

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
John: I do well appreciate your efforts on my behest, However, I pasted the
formuila below into a query and only the CurrMonth portion will return a
result. When I add the PriorMonth portion, it gives me an error "Syntax
Error (missing operator)". I think this is do to a conflict on the multiple
date groups. Am I supposed to create 4 separate queries and the 1 more where
I join all the information for the report. Ick!!!

Gary(dash)Mitchell(at)live(dot)com

John said:
SELECT Customer

, SUM(IIF(SomeDate Between DateSerial(Year(Date()),Month(Date()),1) AND
Date(),Amount, Null)) as CurrMonth

,SUM(IIF(SomeDate Between DateSerial(Year(Date())-1,Month(Date()),1) AND
DateSerial(Year(Date())-1,Month(Date(),Day(Date()),Amount, Null)) as PriorMonth

,SUM(IIF(SomeDate Between DateSerial(Year(Date()),1,1) AND Date()) as CurrYear

,SUM(IIF(SomeDate Between DateSerial(Year(Date())-1,1,1) AND
DateSerial(Year(Date())-1,Month(Date(), Day(Date()),Amount, Null)) as PriorYear

FROM SomeTable
WHERE SomeDate Between DateSerial(Year(Date())-1,1,1) and Date()
GROUP BY Customer

If you want the end of the month instead of the current date, you will have to
adjust the criteria used.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
I need to create a YTD Report in the following format:
[quoted text clipped - 15 lines]
extract the numbers from my query and total them on the report? Please help!!
! The hair I haven't pulled out is completely gray.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top