0

有没有人想出如何将其调整为财政日历?代码看起来像这样。

[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')

DERIVE FIELDS FROM FIELDS [StartDate] USING [autoCalendar] ;
4

2 回答 2

0

因此,查看您对另一个答案的评论,您的财政年度不是 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] ;
于 2016-09-19T12:30:26.177 回答
0

根据您的会计年度开始时间,您需要一些稍微不同的东西。基本上只需在日期上增加 9 个月即可获得财政年度,然后适应季度......

假设您的财政年度从 4 月开始,您可能需要以下内容:

 Dual(Year(Addmonths($1,9)),Makedate(Year(Addmonths($1,9))-1,4,1)) AS [Year] Tagged ('$axis', '$year')
 // e.g. text value will be 2017 and num value will be 01/04/2016 for 01/04/2016 to 31/03/2017

,Dual('Q'&Num(if(Num(Month($1))<=3,4,Ceil(Num(Month($1))/3)-1)),Num(if(Num(Month($1))<=3,4,Ceil(Num(Month($1))/3)-1),00)) AS [Quarter] Tagged ('$quarter')

,Dual(Year(Addmonths($1,9))&'-Q'&Num(if(Num(Month($1))<=3,4,Ceil(Num(Month($1))/3)-1)),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')
// Have left this one as-is as generally people want YearMonth to be calendar year

,Dual('W'&Num(Week($1),00), Num(Week($1),00)) AS [Week] Tagged ('$weeknumber')
// Have left this one as-is as not sure whether you'd number this for fiscal or calendar weeks 

,Date(Floor($1)) AS [Date] Tagged ('$date')

DERIVE FIELDS FROM FIELDS [StartDate] USING [autoCalendar] ;

(注意 - 没有直接尝试过这段代码,只是在我不得不手的另一个日历中,所以它可能不只是完美地复制粘贴)

于 2016-09-09T08:57:16.240 回答