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
pmargari
Advocate II
Advocate II

Calculate the average of the first 3 months from last 6 months

Hello
I'm tring to calculate the average of the first 3 months going back 6 months , in the below example and if we pick January
I need to return 6 months and from that period I need to calculate the average of the fist 3 months of this period of 6 months
So for January I need the average of (July,  August and September) , etc as below

Any tips ?
Appreciated

Screenshot 2023-08-02 122120.jpg

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You could use the WINDOW function, something like

Avg first 3 months =
VAR DatesToUse =
    WINDOW (
        -6,
        REL,
        -4,
        REL,
        ALL ( 'Date'[Year month], 'Date'[Year month sort column] ),
        ORDERBY ( 'Date'[Year month sort column] )
    )
VAR Result =
    AVERAGEX (
        DatesToUse,
        CALCULATE (
            [Measure to average],
            ALLEXCEPT ( 'Date', 'Date'[Year month], 'Date'[Year month sort column] )
        )
    )
RETURN
    Result

View solution in original post

3 REPLIES 3
johnt75
Super User
Super User

You could use the WINDOW function, something like

Avg first 3 months =
VAR DatesToUse =
    WINDOW (
        -6,
        REL,
        -4,
        REL,
        ALL ( 'Date'[Year month], 'Date'[Year month sort column] ),
        ORDERBY ( 'Date'[Year month sort column] )
    )
VAR Result =
    AVERAGEX (
        DatesToUse,
        CALCULATE (
            [Measure to average],
            ALLEXCEPT ( 'Date', 'Date'[Year month], 'Date'[Year month sort column] )
        )
    )
RETURN
    Result

Hello johnt75

It works , thanks a lot for your tip !!

Avg first 3 months =

VAR DatesToUse =
WINDOW (
-6,
REL,
-4,
REL,
ALL ( 'Date'[YearMonth], 'Date'[Year-Month Index]),
ORDERBY ( 'Date'[Year-Month Index])
)
VAR Result =
AVERAGEX (
DatesToUse,
CALCULATE (
DIVIDE([# Leads],[# Processos]),
ALLEXCEPT ( 'Date', 'Date'[YearMonth], 'Date'[Year-Month Index] )
)
)
RETURN
    Result

Screenshot 2023-08-02 150253.jpg

 

 

PREVIEW
 
 
 

Thanks for feedback and I'm going to test !! 

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.