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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
seanmcc
Helper I
Helper I

Measure Moving Average last 5 values

Hello,

 

I have a table with values (eg. Eccentric Duration [ms]) for many players over a number of dates. There will not always be a value for every day.

 

I need to create a measure that calculates the rolling average of the most recent 5 values per player.

In my report I will want to use a slicer for Name and Season.

If there is less than 5 values filtered then average values available.

 

NameSeasonDateTrialEccentric Duration [ms]Rolling Average of 5
Player 12020/2117/08/2020Mean337 
Player 12020/2122/08/2020Mean372354.5
Player 12020/2107/10/2020Mean356355
Player 12020/2102/11/2020Mean338350.75
Player 12020/2111/11/2020Mean395359.6
Player 12020/2107/02/2021Mean353362.8
Player 12021/2229/06/2021Mean380364.4
Player 12021/2205/07/2021Mean393371.8
Player 12021/2222/07/2021Mean421388
Player 22020/2117/08/2020Mean510 
Player 22020/2122/08/2020Mean477493.5
Player 22020/2107/10/2020Mean971652.7
Player 22020/2113/10/2020Mean488611.5
Player 22020/2104/06/2021Mean722633.6
Player 22021/2229/06/2021Mean491629.8
Player 22021/2205/07/2021Mean465627.4
Player 22021/2209/07/2021Mean483529.8
Player 22021/2222/07/2021Mean491530
Player 32020/2117/08/2020Mean581 
Player 32020/2122/08/2020Mean483532
Player 32020/2108/09/2020Mean581548.3
Player 32020/2129/09/2020Mean587558
Player 32020/2120/10/2020Mean505547.4
Player 32020/2111/11/2020Mean471525.4
Player 32020/2123/03/2021Mean556540
Player 32021/2229/06/2021Mean500523.8
Player 32021/2205/07/2021Mean513509

 

Rolling Avg 5.PNG

 

I hope I have explained this well enough.

 

Thanks in advance.

 

Sean

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Picture2.png

 

Eccentric duration measure : =
SUM ( Data[Eccentric Duration [ms]]] )
 
Rolling avg of last five : =
VAR _topnnumber = 5
VAR _currentplayer =
MAX ( Players[Name] )
VAR _currentdate =
MAX ( Dates[Date] )
VAR _tableperplayer =
FILTER (
ALLSELECTED( Data ),
Data[Name] = _currentplayer
&& Data[Date] <= _currentdate
)
VAR _topNtable =
TOPN ( _topnnumber, _tableperplayer, CALCULATE ( MAX ( Data[Date] ) ), DESC )
VAR _result =
AVERAGEX ( _topNtable, [Eccentric duration measure :] )
RETURN
IF ( NOT ISBLANK ( [Eccentric duration measure :] ), _result )
 
 
 
 
 

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.


Go to My LinkedIn Page


Hi @Jihwan_Kim 

 

Thanks for the reply.

 

I have tried your solution but am coming up with blank cells.

 

Rolling 5 Blank.PNGModel.PNG

I have used Player No to anonymise names. Perhaps this is causing issues?

 

Please see below the measures I have used. I am unsure where I am going wrong.

I have used average in my measure, as in my full data set there would be more than one 'trial, (eg. mean, trial1, trial2, trial3 etc.) per date per player.

 

Eccentric duration measure: = AVERAGE( 'CMJ PowerBI (2)'[Eccentric Duration [ms]]] )

 

Rolling avg of last five: =
VAR _topnnumber = 5
VAR _currentplayer =
MAX ( 'Players'[Player No] )
VAR _currentdate =
MAX ( 'Calendar'[Date] )
VAR _tableperplayer =
FILTER (
ALLSELECTED( 'CMJ PowerBI (2)'),
'CMJ PowerBI (2)'[Name] = _currentplayer
&& 'CMJ PowerBI (2)'[Date] <= _currentdate)
VAR _topNtable =
TOPN ( _topnnumber, _tableperplayer, CALCULATE ( MAX ( 'CMJ PowerBI'[Date] ) ), DESC )
VAR _result =
AVERAGEX ( _topNtable, [Eccentric duration measure:] )
RETURN
IF ( NOT ISBLANK ( [Eccentric duration measure:] ), _result )
 
Thanks again in advance
Sean

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors