使用Qlik Sense自动日历代码的财政日历

时间:2016-09-09 04:06:41

标签: date calendar qliksense fiscal

有没有人想出如何使其适应财政日历?代码看起来像这样。

[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] ;

2 个答案:

答案 0 :(得分: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] ;

(注意 - 没有直接尝试过此代码,只是在另一个日历中,我不得不提交,所以它可能不仅仅是完全复制粘贴)

答案 1 :(得分: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] ;