3
votes

In matrix Rows are MM-YY coming from dim_Calendar table. Columns are LossMMYY coming from fact_Data table.

How can I get cumulative total across LossMMYY column and possibly to fill out blanks?

enter image description here

Relationship:

enter image description here

Should be like this:

enter image description here

I tried:

RunningTotal= CALCULATE(
                    PolicyNumberCount,
                    FILTER(
                        ALL(fact_Data[LossDate]),fact_Data[LossDate]<= MAX(dim_Date[Date].[Date])

But unfortunately doesn't work.

For some reason its still doesn't work correctly: .pbix file:

https://www.dropbox.com/s/267m1r3rf98g86e/PRC%20Actuarial%20Report%20-%20Test.pbix?dl=0

                      )
2

2 Answers

2
votes

First create another table using the following 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"
            )
)

Sort [LossMMYY] by [Index Column]

Then add another column to your fact table, using the same logic:

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"
) 

Now you have a valid index from which to compare dates. You can now create a measure using the following 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
        )
    )

Using the new measure in the values parameter of the matrix and the new field 'MMYY'[LossMMYY] in the column parameter will yield the following: enter image description here

oleg, this is what I get when implementing my logic in your .pbix enter image description here

1
votes

enter image description here

You can accomplish this with two new tables, and this formula:

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))

New Table 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" )
)

New Calendar 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" )
)