Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

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

 

 

I hope I have explained this well enough.

 

Thanks in advance.

 

Sean

2 Replies

  •  

    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 )
     
     
     
     
     
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Jihwan_Kim 

       

      Thanks for the reply.

       

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

       

      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