I have a table with year, month, date, project and income columns. Each entry is added on the first of every month.
I have to be able to get the total income for a particular project for every financial year. What I've got so far (which I think kind of works for yearly?) is something like this:
SELECT year, SUM(TotalIncome)
FROM myTable
WHERE ((date Between #1/1/2007# And #31/12/2015#) AND (project='aproject'))
GROUP BY year;
Essentially, rather than grouping the data by year, I would like to group the results by financial year. I have used DatePart('yyyy', date)
and the results are the same.
I'll be running the query from excel to a database. I need to be able to select the number of years (e.g. 2009 to 2014, or 2008 to 2010, etc). I'll be taking the years from user input in excel (taking two dates, i.e. startYear, endYear).
The results from the current query give me, each year would be data from 1st January to 31st December of the same year:
Year | Income
2009 | $123.12
2010 | $321.42
2011 | $231.31
2012 | $426.37
I want the results to look something like this, where each financial year would be 1st July to 30th June of the following year:
FinancialYear | Income
2009-10 | $123.12
2010-11 | $321.42
2011-12 | $231.31
2012-13 | $426.37
If possible, I'd also like to be able to do it per quarter.
Also, if it matters, I have read-only access so I can't make any modifications to the database.