Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
cathoms
Responsive Resident
Responsive Resident

Rolling 12 month average when data is only monthly

Hello, I'm trying to create a rolling average for a mortality index. Mortality index is the the relationship between observed and expected deaths. My data set includes number of cases, number of observed deaths, and number of expected deaths by month. To get the mortality index, I first determine what percent of all cases have an observed death and what percent have an expected death. Then the index is determined by dividing % Observed Deaths by % Expected Deaths. DAX looks like this:

 

 

Total Cases = SUM( 'Patient Outcomes'[encounters] )
Total Obs Deaths = SUM( 'Patient Outcomes'[deaths] )
Total Exp Deaths = SUM( 'Patient Outcomes'[deathsExp] )
%DeathsObs = DIVIDE( [Total Obs Deaths], [Total Cases] )
%DeathsExp = DIVIDE( [Total Exp Deaths], [Total Cases] )
Mortality Index = DIVIDE( [%DeathsObs], [%DeathsExp], 0.00 )

 

 

I have a DateDim table connected to my Patient Outcomes fact table by DschMnStDT (Discharge month start date). Sample data:

dischargeMonthDschMnStDTencountersdeathsdeathsExp 
2021-1010/1/202119545974.08 
2021-1111/1/202117968389.72 
2021-1212/1/202118588295.06 
2022-011/1/202218028879.69 
2022-022/1/202218447374.18 
2022-033/1/202220025867.12 
2022-044/1/202219828164.55 
2022-055/1/202221395959.07 
2022-066/1/202219625859.38 
2022-077/1/202220106261.99 
2022-088/1/202220496562.61 
2022-099/1/202220366464.21 
2022-1010/1/202219975262.89 
2022-1111/1/202220136468.91 
2022-1212/1/202221646070.89 
2023-011/1/202321145266.92 
2023-022/1/202318425672.46 
2023-033/1/202321945768.55 
2023-044/1/202322326272.79 
2023-055/1/202323846673.35 
2023-066/1/202323045974.17 
2023-077/1/202322245367.66 
2023-088/1/202323735970.03 
2023-099/1/202321975060.06 
2023-1010/1/202322126177.20 
2023-1111/1/202322336069.90 
2023-1212/1/202322316971.02 
2024-011/1/202413403353.44 

 

I've tried several variations to get a rolling 12 month average of mortality index but my measures keep returning the Mortality Index for each month. Here is mortality index and my expected result:

dischargeMonthMortality IndexExpected Outcome
2021-100.80 
2021-110.93 
2021-120.86 
2022-011.10 
2022-020.98 
2022-030.86 
2022-041.25 
2022-051.00 
2022-060.98 
2022-071.00 
2022-081.04 
2022-091.000.98
2022-100.830.99
2022-110.930.99
2022-120.850.99
2023-010.780.96
2023-020.770.94
2023-030.830.94
2023-040.850.91
2023-050.900.90
2023-060.800.88
2023-070.780.86
2023-080.840.85
2023-090.830.83
2023-100.790.83
2023-110.860.82
2023-120.970.83
2024-010.620.82
3 REPLIES 3
cathoms
Responsive Resident
Responsive Resident

Here are some of my failed attempts, all of which return the exact same values for only nine months and those values match each month's value:

 

MortIndex R12M = 
VAR _NumMonths = 12
VAR _LastCurrentDate = MAX( DateDim[Date] )
VAR _Period = DATESINPERIOD( DateDim[Date], _LastCurrentDate, - _NumMonths, MONTH )
VAR _Result =
    CALCULATE(
        AVERAGEX( 
            VALUES( DateDim[Month] ),
            [Mortality Index]
        ),
        _Period
    )
VAR _FirstDateInPeriod = MINX( _Period, DateDim[Date] )
VAR _LastDateWithIndex = MAX( 'Patient Outcomes'[DschMnStDT] )

RETURN
    IF( _FirstDateInPeriod <= _LastDateWithIndex, _Result )

 

 

 

MortIndex R12M v3 = 
CALCULATE(
    [Mortality Index],
    DATESINPERIOD( DateDim[Date], MAX( DateDim[Date] ), -12, MONTH )
)

 

 

 

MortIndex R12M v4 = 
    CALCULATE(
        AVERAGEX(
            VALUES( DateDim[Date] ),
            [Mortality Index]
        ),
        DATESINPERIOD( DateDim[Date], MAX( DateDim[Date] ), - 12, MONTH )
    )

 

 

 

MortIndex R12M v5 = 
VAR _NumMonths = 12
VAR _LastCurrentDate = MAX( DateDim[Date] )
VAR _PeriodToUse = 
    FILTER(
        ALL( DateDim ),
        AND(
            DateDim[Date] > _LastCurrentDate - 365,
            DateDim[Date] <= _LastCurrentDate
        )
    )
VAR _Result =
    CALCULATE(
        AVERAGEX( DateDim, [Mortality Index] ),
        _PeriodToUse
    )
RETURN
    _Result

 

 

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Not really an option for a couple of reasons - the file is fairly large and, more importantly, this involves sensitive data that I cannot share.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.