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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
brockry1
Helper II
Helper II

Dax Command for Rolling 3 Week Average

I'm looking to calculate a rolling 3 week average on my GSV for the last 3 weeks but need it to lag a week.  For the screen shot I would want an average for weeks 10,9 and 8 and when 11 is completed and 12 starts showing I would want 11, 10 and 9 and so on each time a new week starts.  In my data table I brought in the year, period and week.  I did not bring in date but if needed I can.  

 

brockry1_0-1741792862385.png

 

Distribution TypePeriodWeekGSV
VetsourceP025645
Vetsource P026635
Vetsource P027490
Vetsource P028718
VetsourceP039689
VetsourceP0310622
VetsourceP031198
1 ACCEPTED SOLUTION
techies
Super User
Super User

Hi @brockry1 please check this

 

Rolling_3_Week_Avg =
VAR CurrentWeek = MAX('Sales'[Sales Week])
VAR LastCompletedWeek = CurrentWeek - 1


VAR AvailableWeeks =
TOPN(3,
FILTER(ALL('Sales'), 'Sales'[Sales Week] <= LastCompletedWeek),
'Sales'[Sales Week], DESC
)

VAR AvgGSV =
AVERAGEX(AvailableWeeks, 'Sales'[GSV])

RETURN
AvgGSV

― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

View solution in original post

7 REPLIES 7
v-hashadapu
Community Support
Community Support

Hi @brockry1 ,
I hope the information shared was helpful. If you have any additional questions or would like to explore the topic further, feel free to reach out. If any of the responses resolved your issue, please mark it "Accept as solution" and give it a 'Kudos' to support other members in the community.
Thank you!

v-hashadapu
Community Support
Community Support

Hi @brockry1 , Just checking in—were you able to resolve the issue?
If one of the replies helped, please consider marking it as "Accept as Solution" and giving a 'Kudos'. Doing so can assist other community members in finding answers more quickly.
Thank you!

v-hashadapu
Community Support
Community Support

Hi @brockry1 , Thank you for reaching out to the Microsoft Community Forum.

Please let us know if your issue is solved. If it is, consider marking the answers that helped 'Accept as Solution', so others with similar queries can find them easily. If not, please share the details.
Thank you.

techies
Super User
Super User

Hi @brockry1 please check this

 

Rolling_3_Week_Avg =
VAR CurrentWeek = MAX('Sales'[Sales Week])
VAR LastCompletedWeek = CurrentWeek - 1


VAR AvailableWeeks =
TOPN(3,
FILTER(ALL('Sales'), 'Sales'[Sales Week] <= LastCompletedWeek),
'Sales'[Sales Week], DESC
)

VAR AvgGSV =
AVERAGEX(AvailableWeeks, 'Sales'[GSV])

RETURN
AvgGSV

― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

One of ways to create a measure for finding out recent three-complete-weeks rolling average is using WINDOW DAX function in the measure.

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

Jihwan_Kim_1-1741804734080.png

 

 

Jihwan_Kim_0-1741804687078.png

 

GSV measure: = 
SUM( data[gsv] )

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

complete 3 weeks rolling average: =
VAR _today =
    TODAY ()
VAR _currentweekenddate =
    MAXX (
        FILTER ( 'calendar', 'calendar'[date] = _today ),
        'calendar'[End of Week]
    )
VAR _completeweek = _today = _currentweekenddate
RETURN
    IF (
        _completeweek,
        AVERAGEX (
            WINDOW (
                1,
                ABS,
                3,
                ABS,
                FILTER (
                    ALL ( 'calendar'[End of Week] ),
                    'calendar'[End of Week] <= _currentweekenddate
                ),
                ORDERBY ( 'calendar'[End of Week], DESC )
            ),
            [GSV measure:]
        ),
        AVERAGEX (
            WINDOW (
                1,
                ABS,
                3,
                ABS,
                FILTER (
                    ALL ( 'calendar'[End of Week] ),
                    'calendar'[End of Week] < _currentweekenddate
                ),
                ORDERBY ( 'calendar'[End of Week], DESC )
            ),
            [GSV measure:]
        )
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

So I do have a Calendar Table:

brockry1_0-1741806451416.png

And have a many to one relationship on date to date for my Fact Table to Calendar. 

brockry1_1-1741806507060.png

So the end of week in the sample isn't working. 

Hi,

I still need to understand how your calendar dimension table is structured, for instance, what column is sorted by what column.

Please share your sample pbix file's link, and then, I can try to look into it.

Thank you.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.