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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
nleuck_101
Responsive Resident
Responsive Resident

Getting rolling 3 month average

Hello All,

 

I'm having some trouble getting a rolling 3 month average to work properly. I've tried 5 different formulas and they return either 0 or blank. I have a Date table with the first date as 01/01/1989 and an ending date of 12/31/2027. My data table has EndOfMonth dates, that start on 01/31/2019 and end with 08/31/2022. I summed the data to a monthly total in SQL, to save time from loading all the rows.

 

Here is an example of the last formula I tried to use:

nleuck_101_0-1660064769899.png

 

 

Any help would be greatly appreciated.

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@nleuck_101,

 

Have you tried this pattern?

 

https://www.daxpatterns.com/standard-time-related-calculations/#code61 

 

Sales AVG 3M :=
VAR Period3M =
    CALCULATETABLE (
        DATESINPERIOD (
            'Date'[Date],
            MAX ( 'Date'[Date] ),
            -3,
            MONTH
        ),
        'Date'[DateWithSales] = TRUE
    )
VAR FirstDayWithData =
    CALCULATE (
        MIN ( Sales[Order Date] ),
        REMOVEFILTERS ()
    )
VAR FirstDayInPeriod =
    MINX ( Period3M, 'Date'[Date] )
VAR Result =
    IF (
        FirstDayWithData <= FirstDayInPeriod,
        AVERAGEX (
            Period3M,
            [Sales Amount]
        )
    )
RETURN
    Result

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
DataInsights
Super User
Super User

@nleuck_101,

 

Have you tried this pattern?

 

https://www.daxpatterns.com/standard-time-related-calculations/#code61 

 

Sales AVG 3M :=
VAR Period3M =
    CALCULATETABLE (
        DATESINPERIOD (
            'Date'[Date],
            MAX ( 'Date'[Date] ),
            -3,
            MONTH
        ),
        'Date'[DateWithSales] = TRUE
    )
VAR FirstDayWithData =
    CALCULATE (
        MIN ( Sales[Order Date] ),
        REMOVEFILTERS ()
    )
VAR FirstDayInPeriod =
    MINX ( Period3M, 'Date'[Date] )
VAR Result =
    IF (
        FirstDayWithData <= FirstDayInPeriod,
        AVERAGEX (
            Period3M,
            [Sales Amount]
        )
    )
RETURN
    Result

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.