I recently created a workbook for a customer that uses Year To Date data. The report was made simpler because the customer did not want to use the current month so there was no need to calculate the percentage of the current months work days and then apply that percentage to the current month last year. As with most workbooks the desire here was to automate as much of the data retrieval as possible and this included passing the MS Query the date range for which the query is to be run when the workbook is opened.
The Fiscal Year runs from February through January. From March through December the calculation is easily calculated using the DATE and TODAY functions like this for the beginning date =DATE(YEAR(TODAY()),2,1). This returns February 1st for the current year. The calculation for the ending date would be =DATE(YEAR(TODAY()), MONTH(TODAY())-1,1). This formula returns the first day of last month which is what we want since for our purposes the Year To Date excludes the current month.
These simple formulas work great until the beginning of the new year. In January 2012 the above formulas would produce the following date range February 1, 2012 to December 1, 2011 which is obviously not a valid date range. February also produces an the invalid date range of February 1, 2012 to January 1, 2012.
Looking at these date ranges also brings up the question of what date range should be used when the workbook is run in February of any given year? In February the customer wants to see February of the previous year through January of the current year. In March the date range would be use February only (i.e. February through February).
Additionally the workbook compares data for Year To Date vs. Year To Date Last Year so its necessary to come up with formulas to calculate the beginning and ending date for the previous year.
So, now all you have to do is come up with formulas for the date ranges for the Current Year and the Previous Year.
In the next post I'll show you the formulas that I used in the workbook.
As always, if you have any questions or comments you can leave them here as a comment or email me at randomexcel@att.net.