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
marenecaCZ
Frequent Visitor

Rolling average for weekly values

Hello, 

my table with data has only two columns:

marenecaCZ_0-1680597499700.png

I would like to create a new table (visual) with rolling average measure:

marenecaCZ_1-1680597673963.png

week 9 = average for last 4 weeks

week 10 = average for last 4 weeks

.....

Could you please help me how to do that?

Thank you

2 ACCEPTED SOLUTIONS
v-zhangti
Community Support
Community Support

Hi, @marenecaCZ 

 

You can try the following methods.
Measure:

4 week moving average = 
Var _N1=SUMMARIZE(FILTER(ALL('Table'),[Week]<=MAX('Table'[Week])),[Week],"Sum",SUM('Table'[Count]))
Var _N2=TOPN(4,_N1,[Week],DESC)
Var _Average=DIVIDE(SUMX(_N2,[Sum]),4)
return
IF(COUNTX(_N2,[Sum])<4,BLANK(),_Average)

vzhangti_0-1681972052681.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Hello all,

I found the solution. In my data model, it looks like this:

marenecaCZ_0-1682404541786.png

Thank you all for your help.

Marek

View solution in original post

8 REPLIES 8
v-zhangti
Community Support
Community Support

Hi, @marenecaCZ 

 

You can try the following methods.
Measure:

4 week moving average = 
Var _N1=SUMMARIZE(FILTER(ALL('Table'),[Week]<=MAX('Table'[Week])),[Week],"Sum",SUM('Table'[Count]))
Var _N2=TOPN(4,_N1,[Week],DESC)
Var _Average=DIVIDE(SUMX(_N2,[Sum]),4)
return
IF(COUNTX(_N2,[Sum])<4,BLANK(),_Average)

vzhangti_0-1681972052681.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

 

Hello all,

I found the solution. In my data model, it looks like this:

marenecaCZ_0-1682404541786.png

Thank you all for your help.

Marek

Alf94
Super User
Super User

Hello @marenecaCZ,

 

I think the following may do the trick:

 

 

Rolling Average = 

    VAR rollingValue = -3
    
    RETURN
        IF(
            RANKX(
                ALLSELECTED( 'Table'[Week] ),
                CALCULATE( MAX( 'Table'[Week] ) ),
                ,
                ASC
            )
            > ABS( rollingValue ),
            AVERAGEX(
                WINDOW(
                    rollingValue, REL,
                    0, REL,
                    ORDERBY( 'Table'[Week], ASC )
                ),
                CALCULATE( SUM( 'Table'[Count] ) )
            ),
            BLANK()
        )

 

 

Let me know if this is ok.

Hello @Alf94 , thank you, but it doesn't work. Something is wrong maybe in the ORDERBY function 😞

Marek

@marenecaCZ, can you share more details about what is not working please? It is working on my side, as you can see on this screenshot:

 

Capture d’écran 2023-04-04 115152.png

The ORDERBY function is underlined in red but works, this is a known bug.

@Alf94 , something is wrong in my measure:

 

marenecaCZ_0-1680604752242.png

 

@marenecaCZ, the problem comes from the WINDOW() function. Your version of Power BI Desktop must be at least December 2022 to use this function, which doesn't seem to be the case now. Try upgrading your version and everything should be fine afterwards.

@Alf94 thanks a lot. Unfortuntely I can't upgrade to Dec 2022 version due to some IT restrictions in the company where I work 😞 So I will have to look for another solution. But thanks a lot.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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