使用 Qlik Sense 自动日历代码的会计日历
Posted
技术标签:
【中文标题】使用 Qlik Sense 自动日历代码的会计日历【英文标题】:Fiscal calendar using Qlik Sense auto Calendar code 【发布时间】:2016-09-09 04:06:41 【问题描述】:有没有人想出如何将其调整为财政日历?代码如下所示。
[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] ;
【问题讨论】:
【参考方案1】:根据您的会计年度开始时间,您可能需要一些稍微不同的东西。基本上只需在日期上加上 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] ;
(注意 - 没有直接尝试过这段代码,只是在我手头的另一个日历中,所以它可能不能完美地复制粘贴)
【讨论】:
嗨,Saranjith,感谢您的回答,尽管我仍然无法完全理解正在做些什么来修改它以适应我所拥有的。我的财务日历从 2015 年 12 月 28 日到 2016 年 12 月 25 日开始。而且我还需要周和月来适应变化。因此,1 月的第 1 周从 2015 年 12 月 28 日开始,到 2016 年 1 月 24 日结束。谢谢 @FredAmponsah 你的财政年度是疯狂,brb还有另一个答案,因为这个答案只适用于理智的环境^【参考方案2】:因此,在另一个答案中查看您的 cmets,您的财政年度不是 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] ;
【讨论】:
以上是关于使用 Qlik Sense 自动日历代码的会计日历的主要内容,如果未能解决你的问题,请参考以下文章
Power Query 比较公司具有不同会计年度的会计和日历数据