一起
我如何在PowerPivot中获得它,或者以Dax公式得出我的内部/个人月份从2019年1月31.120.000到2019年1月的每个月初收到的信息? 那么,我已经从2018年12月31日开始在PowerPivot日历表中获得一月,然后在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
最好的问候
答案 0 :(得分:0)
首先,我创建一个日历表,这是简单的部分,我随机地进行了测试:
CalendarDates = CALENDAR(DATE(2012;12;20);DATE(2021;1;5))
然后我将列WeekNumber添加到了公历中。有点复杂,因为Microsoft在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。如果您希望自己的数学有所不同,则需要自己做数学。