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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
JonathanJohns
Helper III
Helper III

Running Average for three weeks

Good afternoon,

 

I have a problem to do a formula with Power BI Desktop. I had a look on the forum to find my answer but I was not able to do the operation.

 

I have a table like this one with data from 01/02/2017 to 31/03/2017. I would like to calculate  a running average for 3 weeks.

 

DATEValueDayWeekMonth
01/03/2017 NA0017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/201760,10017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/201760,310017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/201760,320017-03-010017-W0917-mars
01/03/201760,890017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/2017 NA0017-03-010017-W0917-mars
01/03/201759,890017-03-010017-W0917-mars

 

I know how to calculate an average for one week but I don't know how to do a running average. For an example I would like a table like that :

 

WeekAverageRunning Average
0017-W0960NA
0017-W1061NA
0017-W116261
0017-W126061
0017-W136161
0017-W146160,666666
0017-W156261,333333

 

With for the week 11 the calculation : (60+61+62)/3=61

For the week 12 : (61+62+60)=61

For the week 14 : (60+61+61)=60,66

...

 

I know it won't be possible to calculate for the 2 first weeks but do you know how to do for the others please ?

 

Thanks for your help.

10 REPLIES 10
Anonymous
Not applicable

Hi @JonathanJohns,

In your scenario, you can firstly create new table using the DAX below.

NewTable = SUMMARIZE('Datatable','Datatable'[Week],"Average",AVERAGE('Datatable'[Value]))

Then create a index column in the new table using the following formula. 

Index = CALCULATE(COUNT(NewTable[Week]),ALL(NewTable),FILTER(NewTable,NewTable[Week]<=EARLIER(NewTable[Week])))


And create Running Average using DAX below.

Running Average = IF(NewTable[Index]=1 || NewTable[Index]=2,0,(NewTable[Average]+LOOKUPVALUE(NewTable[Average],NewTable[Index],NewTable[Index]-1)+LOOKUPVALUE(NewTable[Average],NewTable[Index],NewTable[Index]-2))/3)


Thanks,
Lydia Zhang

Hi @Anonymous

 

Thanks for your answer. I have done the script you did and I got this table :

 

Sans titre.png

 

Concerning the column "Running Average", I wanted to know how it's possible to get a column like that please :

 

WeekAverageIndexRunning Average
0017-W0960,3741711NA
0017-W1060,3221052NA
0017-W1160,224279360,30685167
0017-W1260,26567460,27068467
0017-W1360,153548560,214499

 

The value 60,306851167 is the average of the 3 values from the weeks W09,W10,W11.

The value 60,27068467 is the average of the 3 values from the weeks W10,W11, W12.

The value 60,214499 is the average of the 3 values from the weeks W11,W12,W13.

 

 

I hope you know what I mean, I tried all my laste friday but it looks a little bit confused for me.

 

Thank you for your help.

 

Jonathan

 

Anonymous
Not applicable

Hi @JonathanJohns,

Do you create newtable using the first formula? And do you right click the newTable and select "New Column" to apply the third formula?

Thanks,
Lydia Zhang

I have done like you said. I created a new table with the DAX, then created the colum"Index" and finally the column "Running Average" and I got the last table.

Anonymous
Not applicable

Hi @JonathanJohns,

The formulas work as expected in my scenario, could you please share me all the data in  your original table so that I can  test?

1.PNG

Thanks,
Lydia Zhang

How can I do to send you my data please ?

I finally did it ! It was just a little error in the DAX. I get the table I want.

 

Thanks for your help.

 

 

 

Anonymous
Not applicable

Hi @JonathanJohns,

I note that you post another thread for the above new issue, please review Qiuyun's reply and your thread will be tracked in that thread.

Thanks,
Lydia Zhang

Greg_Deckler
Community Champion
Community Champion

Take a look at my article here:

https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149

 

You will need to create another measure that takes the average of averages with an appropriate filter but this technique should work.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

I read your article but I didn't understand how did it in my case... Sorry

 

How is it possible to calculate a running average for three weeks please ?

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