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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ClemFandango
Helper II
Helper II

Moving annual average by 3 months

Hi there,

I have the following date table by year and month. It includes dates from 2020 and is continually updated.

I am trying to create an additional column called MAA that calculates the rolling average of the 'Monthly Total'  every 3 months, but failing terribly. Any ideas?

 

Any help greatly appreciated

 

YearMonthMonthly Total
2020February56
2020April15
2021March49
2021July72
2021April59
2021December31
2021November97
2021January57
2021October51
2021September64
2021May78
2021June64
2021August24
2021February33
2022September63
2022January33
2022April40
1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @ClemFandango 

not sure if i fully get you. 

1) add a calculated column like:

Date = 
VAR _month =
SWITCH(
    [month],
    "January", 1,
    "February", 2,
    "March", 3,
    "April", 4,
    "May", 5,
    "June", 6,
    "July", 7,
    "August", 8,
    "September", 9,
    "October", 10,
    "November", 11,
    12
)
RETURN
DATE([Year], _month, 1)

(or do it in Power Query Editor)

 

2) add a calculated column like:

Column = 
AVERAGEX(
    TOPN(
        3,
        FILTER(    
            data,
            data[date]<=EARLIER(data[date])
        ),
        data[date]
    ),
    [Monthly Total]
)

it worked like:

FreemanZ_0-1682593585931.png

View solution in original post

2 REPLIES 2
ClemFandango
Helper II
Helper II

This is fantastic @FreemanZ 

 

Big thanks

FreemanZ
Super User
Super User

hi @ClemFandango 

not sure if i fully get you. 

1) add a calculated column like:

Date = 
VAR _month =
SWITCH(
    [month],
    "January", 1,
    "February", 2,
    "March", 3,
    "April", 4,
    "May", 5,
    "June", 6,
    "July", 7,
    "August", 8,
    "September", 9,
    "October", 10,
    "November", 11,
    12
)
RETURN
DATE([Year], _month, 1)

(or do it in Power Query Editor)

 

2) add a calculated column like:

Column = 
AVERAGEX(
    TOPN(
        3,
        FILTER(    
            data,
            data[date]<=EARLIER(data[date])
        ),
        data[date]
    ),
    [Monthly Total]
)

it worked like:

FreemanZ_0-1682593585931.png

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors