I have a table where I store order dates YYYY-MM_DD.
How do I create fiscal year and fiscal quarter with the following requirements: Fiscal years:
- start date for Fiscal_Year_2000 is 1999-07-01 and ends on 2000-06-31
- start date for Fiscal_year_2001 is 2000-07-01 and end on 2001-06-31
Fiscal Quarters:
- Fiscal_Quarter_1 for example FY2000 starts 1999-07-01 and ends 1999-09-31
- FQ2, FQ3, FQ4 for FY 2000
- FQ1/2/3/4 for FY2001
I tried
WHERE OrderDate BETWEEN '1999-07-01' and '2001-06-31' DATEADD (month,7,OrderDate) AS [OrderDateNew], DATEPART(Year, [OrderDateNew]) as [FY], DATEPART(QUARTER, dateadd(month,3,[OrderDateNew])) as [FQ]
I am getting some very odd results. Any help is highly appreciated.
Output should be something like:
FY FQ Some other data columns of products, sales etc 2000 1 2000 2 2000 3 2000 4 2001 1 2001 2 2001 3 2001 4
Advertisement
Answer
Just add six months and use the year. For instance, if you want FY 2000:
where year(dateadd(month, 6, orderdate)) = 2000
If you want the FY year and quarter, use the same idea:
select year(dateadd(month, 6, orderdate)) as fyear, datepart(quarter, dateadd(month, 6, orderdate)) as fquarter