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

4wk moving average per group

hello, I am looking to caluclate 4 week moving average on this data set. I want to get the moving average per platform (group)

 can someone pls help me how i can do this?

you can see the  excel table below with the 4wma calculated per platform from wk44 to wk06. how can i do this in powerbi?

 

Thanks for your help. Appreciate it...

 

YYWW*ValuePlatform4WMA
24441.587302A1.587302
24450.198413A0.892857
24461.388889A1.058201
24470.992063A1.041667
24480A0.644841
24490A0.595238
24500A0.248016
24510A0
24520A0
25010A0
25020A0
250318.60119A4.650298
25045.803571A6.10119
250513.07292A9.36942
25062.752976A10.05766
25071.264881A5.723586
24440B0
24450.297619B0.14881
24460B0.099206
24470B0.074405
24480B0.074405
24490B0
24500B0
24510B0
24520B0
25010B0
25020B0
25032.083333B0.520833
25045.555556B1.909722
25050B1.909722
25062.380952B2.50496
24440C0
24450C0
24460C0
24470.297619C0.074405
24480C0.074405
24490C0.074405
24500C0.074405
1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@ZubinB 

 

you can also try to this

 

1. create an order column

order = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Platform]=EARLIER('Table'[Platform])&&'Table'[YYWW*]<=EARLIER('Table'[YYWW*])))
 
2.  create 4WMA column
 
Column =
var _start=if('Table'[order]-3<1,1,'Table'[order]-3)
return AVERAGEX(FILTER('Table','Table'[Platform]=EARLIER('Table'[Platform])&&'Table'[order]>=_start&&'Table'[order]<=EARLIER('Table'[order])),'Table'[Value])
11.PNG
pls see the attachment below
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

9 REPLIES 9
ryan_mayu
Super User
Super User

@ZubinB 

 

you can also try to this

 

1. create an order column

order = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Platform]=EARLIER('Table'[Platform])&&'Table'[YYWW*]<=EARLIER('Table'[YYWW*])))
 
2.  create 4WMA column
 
Column =
var _start=if('Table'[order]-3<1,1,'Table'[order]-3)
return AVERAGEX(FILTER('Table','Table'[Platform]=EARLIER('Table'[Platform])&&'Table'[order]>=_start&&'Table'[order]<=EARLIER('Table'[order])),'Table'[Value])
11.PNG
pls see the attachment below
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks a lot @ryan_mayu Ryan. I was exactly trying to do that... create an index first and create moving average .. but i was struggling. thanks for the solution.. i really appreciate it..

you are welcome





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




techies
Super User
Super User

Hi @ZubinB please try this

VAR CurrentWeek = SELECTEDVALUE(Sheet1[yyww])
VAR CurrentPlatform = SELECTEDVALUE(Sheet1[Platform])

VAR MovingAverage =
    AVERAGEX(
        FILTER(
            ALLSELECTED(Sheet1),
            Sheet1[Platform] = CurrentPlatform &&
            Sheet1[yyww] <= CurrentWeek &&
            Sheet1[yyww] >= CurrentWeek - 3
        ),
        Sheet1[Value]
    )
RETURN
IF(ISBLANK(MovingAverage), 0, MovingAverage)
― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

Thanks @techies  for helping.. I tried your solution. it is returning me all zeroes. Dont know why. Thanks for the help. I already got the solution from @ryan_mayu 

danextian
Super User
Super User

Hi @ZubinB

Assuming that the four weeks can cross between two years, you will need a separate weeks table that has a column of the weeks' chronological order as you can't simply subtract 3 from the current week. Assuming also that there are only 52 weeks in a year, create this calculated table and relate it to your fact.

Weeks = 
VAR _Weeks =
    SELECTCOLUMNS ( GENERATESERIES ( 1, 52, 1 ), "Week", [Value] )
VAR _year =
    SELECTCOLUMNS ( { 2024, 2025 }, "Year", [Value] )
VAR _crossjoined =
    ADDCOLUMNS (
        CROSSJOIN ( _year, _Weeks ),
        "YYWW", VALUE ( RIGHT ( [Year], 2 ) & FORMAT ( [Week], "00" ) )
    )
RETURN
    ADDCOLUMNS (
        _crossjoined,
        "Order", RANKX ( _crossjoined, [YYWW],, asc, DENSE )
    )

danextian_1-1740031854975.png

 

Create this measure:

4 WMA = 
VAR _period =
    FILTER (
        ALL ( Weeks ),
        Weeks[Order]
            >= MAX ( Weeks[Order] ) - 3
            && Weeks[Order] <= MAX ( Weeks[Order] )
    )
VAR _AVG =
    AVERAGEX ( _period, CALCULATE ( SUM ( 'Table'[Value] ) ) )
RETURN
    _AVG

 

Please see the attached sample pbix.

 

If this isn't what you're looking for, please provide more details as we'll just end up with assumptions.

danextian_0-1740031770992.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thanks @danextian  for the solution. Let me try this over and get back to you. 

ZubinB
Frequent Visitor

Hi @Abhilash_P  

Thank you for taking the time in answering the question.

It didn't return any error but it dint give any numbers. it created 4WMA column with blanks.

what am i doing wrong? sorry im a beginner in powerbi..

 

 

Thanks

Abhilash_P
Kudo Kingpin
Kudo Kingpin

Hi @ZubinB ,

Can you check with below DAX function


4WMA =
VAR CurrentWeek = SELECTEDVALUE('Table'[YYWW]) -- To Get current YYWW
VAR CurrentPlatform = SELECTEDVALUE('Table'[Platform]) -- To Get current Platform

RETURN
CALCULATE(
AVERAGE('Table'[Value]),
FILTER(
ALL('Table'),
'Table'[Platform] = CurrentPlatform &&
'Table'[YYWW] <= CurrentWeek &&
'Table'[YYWW] > CurrentWeek - 4
)
)

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.

Top Solution Authors