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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Previous quarter query

Status
Not open for further replies.

Bubba059

Technical User
Mar 24, 2006
2
CA
I am trying to calculate sales for the previous quarter both this year and for last. I am using the following:

Previous qtr same year

if datepart("q",currentdate)=1 then
datepart("q",{INIDP.INVDAT})=4
and datepart("yyyy",{INIDP.INVDAT})=datepart("yyyy",dateadd("yyyy",-1,currentdate))
else
datepart("q",{INIDP.INVDAT})=datepart("q",dateadd("q",-1,currentdate))
and datepart("yyyy",{INIDP.INVDAT})=datepart("yyyy",currentdate)

Previous qtr last year

if datepart("q",currentdate)=1 then
datepart("q",{INIDP.INVDAT})=4
and datepart("yyyy",{INIDP.INVDAT})=datepart("yyyy",dateadd("yyyy",1,currentdate)-1)
else
datepart("q",{INIDP.INVDAT})=datepart("q",dateadd("q",-2,currentdate)-1)
and datepart("yyyy",{INIDP.INVDAT})=datepart("yyyy",currentdate)-1

This wroked fine for when I ran it in June but now after running it in July the qtr 1 numbers for this year and last year are different than what I got when I ran it in June.

Thanks in advance.
 
Sorry but made a mistake in the second formula.

if datepart("q",currentdate)=1 then
datepart("q",{INIDP.INVDAT})=4
and datepart("yyyy",{INIDP.INVDAT})=datepart("yyyy",dateadd("yyyy",1,currentdate)-1)
else
datepart("q",{INIDP.INVDAT})=datepart("q",dateadd("q",-2,currentdate)-1)
and datepart("yyyy",{INIDP.INVDAT})=datepart("yyyy",currentdate)-1

Should be -1 and not -2 for the second last line
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top