每个月的个人开始日期

Individual start date per month

一起

如何在 PowerPivot 或 Dax 公式中获取我的内部/个人月份从 2018 年 12 月 31 日开始的 2019 年 1 月收到的信息? 那么,我已经从 2018 年 12 月 31 日开始在 PowerPivot 日历 table 中获得一月,​​然后在 4-4-5 周的周期中? 所以

31.12.2018 + 28 days = January
31.12.2018 + (28 days * 2) = February
31.12.2018 + (28 days * 2) + 7 days = March

有人知道吗?

此致

首先我创建了一个日历table,这是简单的部分,我随机开始和结束进行测试:

CalendarDates = CALENDAR(DATE(2012;12;20);DATE(2021;1;5))

然后我添加了列 WeekNumber,这是公历。有点复杂,因为微软只是在 1 月 1 日从 1 开始计数..

WeekNumber = 
var wNrfirstDayJanNextYear = WEEKNUM(DATE(CalendarDates[Date].[Year] + 1;1;1);2)
var fullWeekNextYear = WEEKNUM(DATE(CalendarDates[Date].[Year] + 1;1;7);2) = 1 //If day 7 of week is still first week, its a full week
var wNr31Dex = WEEKNUM(DATE(CalendarDates[Date].[Year];12;31);2)
var wNr31DexPrevYear = WEEKNUM(DATE(CalendarDates[Date].[Year]-1;12;31);2)
var wNr = WEEKNUM(CalendarDates[Date];2)
var pbi4JanWeekNrNextYear = WEEKNUM(DATE(CalendarDates[Date].[Year] + 1;1;4);2)
var pbi4JanWeekNr = WEEKNUM(DATE(CalendarDates[Date].[Year];1;4);2)
var wNrComp = if (pbi4JanWeekNr =2; wNr - 1; wNr)
return if(NOT(fullWeekNextYear) && wNr = wNr31Dex;IF(pbi4JanWeekNrNextYear = 2; wNr31Dex;1);if(wNrComp = 0; wNr31DexPrevYear; wNrComp))

最后一步是根据周数创建月份:

Month = 
var quater = FLOOR((CalendarDates[WeekNumber] - 1)/13; 1)
var quarterWeek = MOD(CalendarDates[WeekNumber] - 1 - (quater*13);13)
var monthNr = FLOOR(quarterWeek/4;1)
var month445 = if (monthNr = 3; 2; monthNr) + quater * 3 + 1
return if (month445 = 13; 12;month445)

注意:我在上个季度更正了第 53 周,因此它变成了 4-4-6。如果你想要不同,你需要自己做数学。

最终结果: