Fiscal year reporting in SQL Reporting Services (and CRM)

Posted by (JavaScript must be enabled to view this email address) on Tue 28 Jul 2009

The first thing to do is get the current month:


  1. SET @CurrentDate = GetDate()SET @CurrentMonth = Month(@CurrentDate)

Then its just a case of setting the start and end of the fiscal year according to whether the month falls in the last quarter (Jan, Feb, Mar) or the first three quarters (April thru to Dec):

  1. IF @CurrentMonth >= 4
  2. BEGIN
  3. SET @FiscalYearStart = DATEADD(mm, 3, DATEADD(yyyy, DATEDIFF(yyyy, 0, @CurrentDate), 0))
  4. SET @FiscalYearFinish = DATEADD(mm, -1, DATEADD(yyyy, 1, @FiscalYearStart))
  5. END
  6. ELSE
  7. BEGIN
  8. SET @FiscalYearStart = DATEADD(mm, -9, DATEADD(yyyy, DATEDIFF(yyyy, 0, @CurrentDate), 0))
  9. SET @FiscalYearFinish = DATEADD(mm, -1, DATEADD(yyyy, 1, @FiscalYearStart))
  10. END

Hope this helps you in your report building duties full code below:

  1. Declare @CurrentDate AS DateTime
  2. Declare @CurrentMonth AS int
  3. Declare @FiscalYearStart AS DateTime
  4. Declare @FiscalYearFinish AS DateTime
  5. SET @CurrentDate = GetDate()
  6. SET @CurrentMonth = Month(@CurrentDate)
  7. IF @CurrentMonth >= 4
  8. BEGIN
  9. SET @FiscalYearStart = DATEADD(mm, 3, DATEADD(yyyy, DATEDIFF(yyyy, 0, @CurrentDate), 0))
  10. SET @FiscalYearFinish = DATEADD(mm, -1, DATEADD(yyyy, 1, @FiscalYearStart))
  11. END
  12. ELSE
  13. BEGIN
  14. SET @FiscalYearStart = DATEADD(mm, -9, DATEADD(yyyy, DATEDIFF(yyyy, 0, @CurrentDate), 0))
  15. SET @FiscalYearFinish = DATEADD(mm, -1, DATEADD(yyyy, 1, @FiscalYearStart))
  16. END
  17. SELECT @FiscalYearStart, @FiscalYearFinish

Your Comments

Post a Comment

Name

Email Address

Website

Remember my personal information

Notify me of follow-up comments?

Please enter the word you see in the image below:


← Back to Blog Homepage

About our Blog

Brantas Limited specialise in Dynamics CRM, SharePoint and System Integration using the Microsoft Platform. We are all experienced developers in various fields with our own specialities complementing those of our team.

We have been working with SharePoint since 2003, including Installation and Administration, Migration, Development and Support.

Related Solutions

    No Related Posts Found

Related Case Studies

    No Related Posts Found