在矩阵中,行MM-YY
来自dim_Calendar
表。
列是LossMMYY
表中的fact_Data
。
如何获取LossMMYY
列中的累计总数,并可能填补空白?
关系:
应该是这样的:
我尝试过:
RunningTotal= CALCULATE(
PolicyNumberCount,
FILTER(
ALL(fact_Data[LossDate]),fact_Data[LossDate]<= MAX(dim_Date[Date].[Date])
但不幸的是,这不起作用。
由于某种原因,它仍然无法正常工作: .pbix文件:
https://www.dropbox.com/s/267m1r3rf98g86e/PRC%20Actuarial%20Report%20-%20Test.pbix?dl=0
)
答案 0 :(得分:1)
您可以使用两个新表和以下公式来完成此操作:
Count of x =
VAR eDate = SELECTEDVALUE(EffectiveCalendar[MM-YY])
VAR lDate = MAX('LossCalendar'[Date])
RETURN
CALCULATE(COUNT(fact_Data[PolicyNumberCount])
, FILTER(fact_Data, fact_Data[EffectiveMMYY] = eDate && 'fact_Data'[LossDate].[Date] <= lDate))
新表1:
EffectiveCalendar =
ADDCOLUMNS (
CALENDAR (MIN(fact_Data[EffectiveDate]),MAX(fact_Data[EffectiveDate])),
"DateAsInteger", FORMAT ( [Date], "YYYYMMDD" ),
"MonthAsInteger", FORMAT ( [Date], "YYYYMM" ),
"Year", YEAR ( [Date] ),
"Month Number", month([Date]),
"Year/Month", FORMAT ( [Date], "YYYY/MM" ),
"YearMonthShort", FORMAT ( [Date], "YYYY/mmm" ),
"MM-YY", FORMAT ( [Date], "MMM-YY" ),
"Month", FORMAT ( [Date], "mmm" ),
"MonthNameLong", FORMAT ( [Date], "mmmm" ),
"DayOfWeekNumber", WEEKDAY ( [Date] ),
"DayOfWeek", FORMAT ( [Date], "dddd" ),
"DayOfWeekShort", FORMAT ( [Date], "dddd" ),
"Quarter", "Q" & FORMAT ( [Date], "Q" ),
"YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q" & FORMAT ( [Date], "Q" )
)
新日历2:
LossCalendar =
ADDCOLUMNS (
CALENDAR (MIN(fact_Data[LossDate]),MAX(fact_Data[LossDate])),
"DateAsInteger", FORMAT ( [Date], "YYYYMMDD" ),
"MonthAsInteger", FORMAT ( [Date], "YYYYMM" ),
"Year", YEAR ( [Date] ),
"Month Number", month([Date]),
"Year/Month", FORMAT ( [Date], "YYYY/MM" ),
"YearMonthShort", FORMAT ( [Date], "YYYY/mmm" ),
"MM-YY", FORMAT ( [Date], "MMM-YY" ),
"Month", FORMAT ( [Date], "mmm" ),
"MonthNameLong", FORMAT ( [Date], "mmmm" ),
"DayOfWeekNumber", WEEKDAY ( [Date] ),
"DayOfWeek", FORMAT ( [Date], "dddd" ),
"DayOfWeekShort", FORMAT ( [Date], "dddd" ),
"Quarter", "Q" & FORMAT ( [Date], "Q" ),
"YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q" & FORMAT ( [Date], "Q" )
)
答案 1 :(得分:1)
首先使用以下DAX创建另一个表:
MMYY =
SUMMARIZECOLUMNS (
fact_Data[LossMMYY],
"Index Column",
VAR YearNumber =
RIGHT ( VALUES ( fact_Data[LossMMYY] ), 2 ) + 2000
VAR CurrentMonthName =
LEFT ( VALUES ( fact_Data[LossMMYY] ), 3 )
RETURN
YearNumber
& SWITCH (
CurrentMonthName,
"JAN", "01",
"FEB", "02",
"MAR", "03",
"APR", "04",
"MAY", "05",
"JUN", "06",
"JUL", "07",
"AUG", "08",
"SEP", "09",
"OCT", "10",
"NOV", "11",
"DEC", "12"
)
)
按[索引列]排序[LossMMYY]
然后使用相同的逻辑在事实表中添加另一列:
Index Column =
VAR YearNumber =
RIGHT ( 'fact_Data'[LossMMYY], 2 ) + 2000
VAR CurrentMonthName =
LEFT ( 'fact_Data'[LossMMYY], 3 )
RETURN YearNumber &
SWITCH (
CurrentMonthName,
"JAN", "01",
"FEB", "02",
"MAR", "03",
"APR", "04",
"MAY", "05",
"JUN", "06",
"JUL", "07",
"AUG", "08",
"SEP", "09",
"OCT", "10",
"NOV", "11",
"DEC", "12"
)
现在您有了一个有效的索引,可以从中比较日期。您现在可以使用以下DAX创建度量:
Running Total =
VAR CurrentDate =
MAX ( MMYY [Index Column] )
RETURN
CALCULATE (
SUM ( fact_Data[PolicyNumberCount] ),
FILTER (
ALL (fact_Data[Index Column] ),
fact_Data[Index Column] <= CurrentDate
)
)