Hi All,
Currently, I am developing a simple report where business want see Open Opportunities (based on est.close date)in current fiscal year (not calendar year)
As Fiscal settings in CRM are not tied up with opportunity records, I have to build a query for this which is as below.
Our fiscal year is between 1st July and 30th June.
When I use Advanced Find to compare my result set with below query, they are not matched. (below query gives me more result)
Can someone please help me to figure it out what's wrong in this query?
SELECT name, estimatedclosedate, CASE WHEN DATEPART(m,estimatedclosedate) >=7 THEN (DATEPART(YEAR,estimatedclosedate))+1 ELSE DATEPART(YEAR,estimatedclosedate) END AS [FiscalYear] FROM FilteredOpportunity --where(CONVERT(varchar(20),estimatedclosedate,112) >= ('20140701') and (CONVERT(varchar(20),estimatedclosedate,112)<= ('20150630'))) WHERE ( CONVERT(varchar(10),estimatedclosedate,112) >= CASE WHEN DATEPART(m,estimatedclosedate) >=7 THEN DATEFROMPARTS (YEAR(GetDate()),07,01) ELSE DATEFROMPARTS (YEAR(GetDate())-1,07,01) END AND estimatedclosedate <= CASE WHEN DATEPART(m,estimatedclosedate) >=7 THEN DATEFROMPARTS (YEAR(GetDate()) + 1,06,30) ELSE DATEFROMPARTS (YEAR(GetDate()),06,30) END ) AND statecodename = 'Open'
I am using CASE statements to implement the logic where if month of the 'estimated close date' field is greater than or equal to 7 then use current calendar year as beginning of fiscal year or take last calendar year as beginning of the year.
If someone can test this query in their environment to check whether it brings the correct result then it would be great.
Below is my Advanced Find query to compare against:
Thanks for your help.
-H.Desai