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.
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.