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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
nleuck_101
Resolver III
Resolver III

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.