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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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