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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Nawaz
Frequent Visitor

Help with windows function to calculate running AVG

I'm a biginer in Power BI, so please ignore silly mistakes.
I have tried below DAX calculation to calculate the running avg using windows and it does not work.

WindowAVG =
AVERAGEX(
WINDOW(-1,REL,0,REL,
   SUMMARIZE(
            ALLSELECTED(Sheet1),
            Sheet1[category]
        )
        ),[sales]
)


Nawaz_0-1718218970585.png



Thanks,

Nawaz

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Nawaz 

 

Thanks for the reply from @Greg_Deckler , please allow me to provide another insight:


Here I create a set of sample:

vzhengdxumsft_0-1718249596386.png

Then create 2 measures:

SUM_Sales =
VAR _currentCa =
    SELECTEDVALUE ( 'Table'[Category] )
RETURN
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Category] = _currentCa )
    )
AVG =
VAR _vtable =
    SUMMARIZE ( ALLSELECTED ( 'Table' ), 'Table'[Category], "_SUM", [SUM_Sales] )
VAR _vtable2 =
    ADDCOLUMNS ( _vtable, "_sort", RANKX ( _vtable, 'Table'[Category],, ASC ) )
VAR _vtable3 =
    ADDCOLUMNS (
        _vtable2,
        "_AVG",
            AVERAGEX (
                FILTER (
                    _vtable2,
                    [_sort] <= EARLIER ( [_sort] )
                        && [_sort]
                            >= EARLIER ( [_sort] ) - 1
                ),
                [_SUM]
            )
    )
RETURN
    MAXX (
        FILTER ( _vtable3, [Category] = SELECTEDVALUE ( 'Table'[Category] ) ),
        [_AVG]
    )

The result is as follow:

vzhengdxumsft_1-1718249664009.png

 

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Nawaz 

 

Thanks for the reply from @Greg_Deckler , please allow me to provide another insight:


Here I create a set of sample:

vzhengdxumsft_0-1718249596386.png

Then create 2 measures:

SUM_Sales =
VAR _currentCa =
    SELECTEDVALUE ( 'Table'[Category] )
RETURN
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Category] = _currentCa )
    )
AVG =
VAR _vtable =
    SUMMARIZE ( ALLSELECTED ( 'Table' ), 'Table'[Category], "_SUM", [SUM_Sales] )
VAR _vtable2 =
    ADDCOLUMNS ( _vtable, "_sort", RANKX ( _vtable, 'Table'[Category],, ASC ) )
VAR _vtable3 =
    ADDCOLUMNS (
        _vtable2,
        "_AVG",
            AVERAGEX (
                FILTER (
                    _vtable2,
                    [_sort] <= EARLIER ( [_sort] )
                        && [_sort]
                            >= EARLIER ( [_sort] ) - 1
                ),
                [_SUM]
            )
    )
RETURN
    MAXX (
        FILTER ( _vtable3, [Category] = SELECTEDVALUE ( 'Table'[Category] ) ),
        [_AVG]
    )

The result is as follow:

vzhengdxumsft_1-1718249664009.png

 

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Community Champion
Community Champion

@Nawaz Try one of these approaches. Better Rolling Average - Microsoft Fabric Community

 

Or this one, just replace SUMX with AVERAGEX: Better Running Total - Microsoft Fabric Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.