Hi SBASYE;
I had the same issue but the real problem is with the FiscalCalendarView. I will give you the original view structure and the one I amended:
Original View:
================
ALTER VIEW [dbo].[FiscalCalendarView]
AS
SELECT TOP 100000 RANK() OVER(ORDER BY PER.OrganizationId, FY.Starts, FY.Ends, PER.Starts, PER.Ends) as PeriodSequenceNumber,
RANK() OVER(PARTITION BY FY.Id, PER.OrganizationId ORDER BY PER.Starts) as PeriodNumber,
PER.Id, PER.Starts as PeriodStart, PER.Ends as PeriodEnd, FY.Starts as YearStart, FY.Ends as YearEnd,
CAST((SELECT MIN(YEAR(Years.Ends)) FROM FiscalYear Years WHERE Years.OrganizationId = FY.OrganizationId) + DENSE_RANK() OVER(PARTITION BY PER.OrganizationId ORDER BY FY.Starts) -1 AS Int) As FiscalYear,
IsHistorical, PER.IsClosed, PER.OrganizationId
FROM Period PER INNER JOIN FiscalYear FY ON PER.FiscalYearId = FY.Id AND PER.OrganizationId = FY.OrganizationId
ORDER BY PER.Starts
GO
The above View will give you a year ahead.
but the View below will give you what you might be actually looking for:
Altered View
==========
ALTER VIEW [dbo].[FiscalCalendarView]
AS
SELECT TOP 100000 RANK() OVER(ORDER BY PER.OrganizationId, FY.Starts, FY.Ends, PER.Starts, PER.Ends) as PeriodSequenceNumber,
RANK() OVER(PARTITION BY FY.Id, PER.OrganizationId ORDER BY PER.Starts) as PeriodNumber,
PER.Id, PER.Starts as PeriodStart, PER.Ends as PeriodEnd, FY.Starts as YearStart, FY.Ends as YearEnd,
CAST((SELECT MIN(YEAR(Years.Ends)) FROM FiscalYear Years WHERE Years.OrganizationId = FY.OrganizationId) + DENSE_RANK() OVER(PARTITION BY PER.OrganizationId ORDER BY FY.Starts) -2 AS Int) As FiscalYear,
IsHistorical, PER.IsClosed, PER.OrganizationId
FROM Period PER INNER JOIN FiscalYear FY ON PER.FiscalYearId = FY.Id AND PER.OrganizationId = FY.OrganizationId
ORDER BY PER.Starts
GO
change:
=======
DENSE_RANK() OVER(PARTITION BY PER.OrganizationId ORDER BY FY.Starts) -1 AS Int) As FiscalYear ---Original
DENSE_RANK() OVER(PARTITION BY PER.OrganizationId ORDER BY FY.Starts) -2 AS Int) As FiscalYear --- Change
I hope this will help you.