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

View all the Fabric Data Days sessions on demand. View schedule

Reply
ar-data
Helper II
Helper II

4 week rolling/moving average of sum product in dax

I have a table as follows:

Year     Week       Sector     Person       Score

2020W1S1P128
2020W1S1P26
2020W1S1P38
2020W1S1P413
2020W1S2P128
2020W1S2P24
2020W1S2P37
2020W1S2P46
2020W1S3P14
2020W1S3P22

 

Full data here: Data Source 

These are my requirements:

 

1. sector wise average score for the particular week - done as a column as follows

 

Weekly score Average - sector wise = 
CALCULATE( AVERAGE( Table1[score]),
ALLEXCEPT(Table1, Table1[Week], Table1[Sector])
)

 

 

2.  % total of sector wise score to weekly totals ( sum of score of sector for that week / sum of score of all sectors for that week) - done as a column as follows

 

% of sector score to weekly score = 
var a = CALCULATE( SUM( Table1[score] ), ALLEXCEPT( Table1, Table1[Week] ,Table1[Sector] ))
var b = CALCULATE( SUM( Table1[score]), ALLEXCEPT(Table1, Table1[Week]))
return a/b

 

 

3. Ideal Score = Multiply 1 * 2

 

Now I want to calculate the 4 week moving average of Ideal Score (which is a sum product), and this is what I am not able to figure out how to do!

I added a calendar table with date, week and year columns, and then link that with week column of my table with many-many relation. Not sure if this is correct way.

 

Then, I have used the general DatesInPeriod with date column of calender table, with Ideal Score

 

4w rolling average =
VAR NoWeeks = 4
VAR _LastDate = MAX ( 'Calendar'[Date] )
VAR period = DATESINPERIOD ( 'Calendar'[Date], _LastDate, - NoWeeks * 7, DAY )
VAR a = CALCULATE (
        AVERAGE ( 'Table1'[Ideal Score] ),
        ALLEXCEPT ( 'Table1', '1Table'[Week] )
    )
VAR result =  CALCULATE ( a, period )
RETURN a

 

 

But I am not getting the required results. Please help me with this. Thank you.

 

Power Bi file: here 

@v-ljerr-msft I have seen your solution, but did not work for me. Please guide with this -:)

2 REPLIES 2
amitchandak
Super User
Super User

@ar-data , Create a week rank in the date table

 

OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format
measures

 

example measures 
This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

Last 4 weeks = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-4 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak, what I need is 4 week rolling average of sum product of 2 measures. Can you please help me with the formula for this using week rank. Thank you.

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.

Top Solution Authors
Top Kudoed Authors