因此,查看您对另一个答案的评论,您的财政年度不是 365 年,并且每年在不同的一天结束。
下面是来自 Qlikview(创建主日历)的新旧概念与 Qlik Sense 中可用的新功能的混合和匹配。这将为您确定您的年份,但需要更多的工作来确定财政周,但这并不是一个很大的进步。
REM
As Financial Year end varies from year to year, set variables for each to determine when each year ends;
Let varFinYear1 = Date#('28/12/2015','DD/MM/YYYY')
Let varFinYear2 = Date#('25/12/2015','DD/MM/YYYY')
Rem
Generate an entry for every day in your source data table;
Temp:
Load
min(StartDate) as minDate,
max(StartDate) as maxDate
Resident TableNameHere;
Let varMinDate = Num(Peek('minDate', 0, 'Temp'));
Let varMaxDate = Num(Peek('maxDate', 0, 'Temp'));
DROP Table Temp;
TempCalendar:
LOAD
$(varMinDate) + Iterno()-1 As Num,
Date($(varMinDate) + IterNo() - 1) as TempDate
AutoGenerate 1 While $(varMinDate) + IterNo() -1 <= $(varMaxDate);
Rem
Create a map that identifies each year as specified by the variables above, this will need updating for every year;
Map_Calendar:
Mapping Load
TempDate,
if(TempDate<=varFinYear1,'Year1'
,if(TempDate<=varFinYear2,'Year2','Year3')) as FinancialYear
Resident TempCalendar
Order By TempDate ASC;
Drop Table TempCalendar;
Let varMinDate = null();
Let varMaxDate = null();
Rem Now using our map in the autocalendar we can define non 365 Fiscal years;
[autoCalendar]:
DECLARE FIELD DEFINITION Tagged ('$date')
Dual(Year($1), YearStart($1)) AS [Year] Tagged ('$axis', '$year')
,Dual('Q'&Num(Ceil(Num(Month($1))/3)),Num(Ceil(NUM(Month($1))/3),00)) AS [Quarter] Tagged ('$quarter')
,Dual(Year($1)&'-Q'&Num(Ceil(Num(Month($1))/3)),QuarterStart($1)) AS [YearQuarter] Tagged ('$axis', '$yearquarter')
,Month($1) AS [Month] Tagged ('$month')
,Dual(Year($1)&'-'&Month($1), monthstart($1)) AS [YearMonth] Tagged ('$axis', '$yearmonth')
,Dual('W'&Num(Week($1),00), Num(Week($1),00)) AS [Week] Tagged ('$weeknumber')
,Date(Floor($1)) AS [Date] Tagged ('$date')
,ApplyMap('Map_Calendar',$1) as [FiscalYear]
DERIVE FIELDS FROM FIELDS [StartDate] USING [autoCalendar] ;