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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jags8386
New Member

Create rolling average by day of week and then sum at week level

I have following table. 

 

Record DateItem Count
2/25/2024504
2/26/2024516
2/27/2024617
2/28/2024700
2/29/2024987
3/1/2024727
........
.......
......
3/15/2024893
3/16/2024891
3/17/2024779
3/18/2024810
3/19/2024648
3/20/2024784


From this I am calculating rolling  week average for same day of week. For example for date 3/24/2024, it should be rolling average of 2/25/24, 3/3/24, 3/10/24 and 3/17/24

2/25/2024504
3/3/2024757
3/10/2024630
3/17/2024779
  
Rolling avg for 3/24667.5


I am able to calculate this for individual dates. But My total is 731.8 in below example instead of 2069.8

3/24/2024667.5
3/25/2024670.5
3/26/2024731.8
  
Total2069.8

 

 

 

Last4weekAvg = 

var SelectDate = MAX(DATE_TABLE[D_DATE])
var v1 = 
    CALCULATE(
        [Total_Items], 
        FILTER(
           all( DATE_TABLE), 
             DATE_TABLE[D_DATE] >= SelectDate - 28
             && WEEKDAY( DATE_TABLE[D_DATE], 1 ) = WEEKDAY( SelectDate, 1 )
                &&  DATE_TABLE[D_DATE] < SelectDate
        )
    )
return v1

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @audreygerred ,

Thanks for your sharing.

Hi @jags8386 ,

I have created a simple sample, please refer to my pbix file to see if it helps you.

Create 2 columns.

weekday = WEEKDAY('Table'[date],2)
weeknum = WEEKNUM('Table'[date],11)

Then create a measure.

Measure = var _1=SELECTEDVALUE(datetable[Date])
var _1weeknum=WEEKNUM(_1,11)
var _1weekday=WEEKDAY(_1,2)
RETURN
CALCULATE(AVERAGE('Table'[value]),FILTER(ALL('Table'),'Table'[weeknum]<=_1weeknum&&'Table'[weeknum]>=_1weeknum-3&&'Table'[weekday]=_1weekday))

vrongtiepmsft_0-1712731237391.png

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

3 REPLIES 3
Anonymous
Not applicable

Hi @audreygerred ,

Thanks for your sharing.

Hi @jags8386 ,

I have created a simple sample, please refer to my pbix file to see if it helps you.

Create 2 columns.

weekday = WEEKDAY('Table'[date],2)
weeknum = WEEKNUM('Table'[date],11)

Then create a measure.

Measure = var _1=SELECTEDVALUE(datetable[Date])
var _1weeknum=WEEKNUM(_1,11)
var _1weekday=WEEKDAY(_1,2)
RETURN
CALCULATE(AVERAGE('Table'[value]),FILTER(ALL('Table'),'Table'[weeknum]<=_1weeknum&&'Table'[weeknum]>=_1weeknum-3&&'Table'[weekday]=_1weekday))

vrongtiepmsft_0-1712731237391.png

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

 

 

 

 

jags8386
New Member

AverageItemCount = AVERAGEX(ALL('YourTable'), SUM('Table'[item count]))

Is above mesure caculate rolling 4 week average for given weekday? for example, monday will be rolling average of last 4 mondays.

audreygerred
Super User
Super User

Hi! You'll want to use iterator functions to tackle this. Here is a blog article I wrote that explains how these work in more detail: http://powerbiwithme.com/2023/11/01/the-iterator-edition/

 

First, for the average measure:

AverageItemCount = AVERAGEX(ALL('YourTable'), SUM('Table'[item count])) <-- if you have a measure already created for the sum of ItemCount you can use that here instead.
 
Now, the measure that will show you the average per row, but a sum for your subtotals and totals:
SumOfAverageItemCount = SUMX(VALUES('YourTable'), [AverageItemCountPerRow])
 
audreygerred_0-1712248823521.png

If you want subtotals at a weekly level, just add a week number to your visual and you can have your subtotals show for the week level 🙂





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

Proud to be a Super User!





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.