Forum Discussion

michaeldonnelly's avatar
michaeldonnelly
Frequent Visitor
6 years ago
Solved

Rolling/Moving Average - Sports form guide

HI all, im looking to create a rolling average of the last 6 matches played by a team, so in the data below, what are the average points per game from the last 6, obviously this would be different per team. I can do this in tableau without much fuss, seems to be difficult in power BI, I can share the file if needed, i basically want to show this information on a line graph to help me spot trends

 

 

Team NameDatePoints
Aberdeen04/08/20193
Aberdeen11/08/20190
Aberdeen24/08/20191
Aberdeen31/08/20193
Aberdeen14/09/20191
Aberdeen21/09/20193
Aberdeen28/09/20190
Aberdeen05/10/20191
Aberdeen19/10/20193
Aberdeen27/10/20190
Aberdeen30/10/20193
Aberdeen02/11/20193
Aberdeen09/11/20193
Aberdeen24/11/20191
Aberdeen30/11/20193
Aberdeen04/12/20191
Aberdeen07/12/20190
Aberdeen14/12/20193
Aberdeen21/12/20190
Aberdeen26/12/20193
Aberdeen29/12/20191
Accrington03/08/20190
Accrington17/08/20191
Accrington20/08/20190
Accrington24/08/20190
Accrington31/08/20193
Accrington07/09/20191
Accrington14/09/20190
Accrington17/09/20191
Accrington21/09/20191
Accrington28/09/20193
Accrington05/10/20191
Accrington12/10/20190
Accrington20/10/20193
Accrington23/10/20190
Accrington26/10/20190
Accrington02/11/20191
Accrington16/11/20190
Accrington23/11/20193
Accrington07/12/20191
Accrington14/12/20193
Accrington21/12/20191
Accrington26/12/20193
Accrington29/12/20193

 

 

  • mwegener's avatar
    mwegener
    6 years ago

    Hi michaeldonnelly ,

     

    try this.

    Rolling AVG Points last 6 matches =
    CALCULATE (
        AVERAGE ( 'Table'[Points] ),
        TOPN (
            6,
            FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] <= MAX ( 'Table'[Date] ) ),
            'Table'[Date], DESC
        )
    )

     

    Regards,

    Marcus

    Dortmund - Germany
    If I answered your question, please mark my post as solution, this will also help others.
    Please give Kudos for support.

6 Replies

  • az38's avatar
    az38
    Icon for Community Champion rankCommunity Champion

    hi michaeldonnelly 

    you could create a measure like this if I undersyant correct "rolling average"

    Measure = 
    calculate(average(Table1[Points]);TOPN(6;filter(ALL(Table1);Table1[Date]<=SELECTEDVALUE(Table1[Date]) && Table1[Team Name]=selectedvalue('Table1'[Team Name]));Table1[Date];DESC))

    do not hesitate to give a kudo to useful posts and mark solutions as solution

  • mwegener's avatar
    mwegener
    Icon for Most Valuable Professional rankMost Valuable Professional

    Hi michaeldonnelly ,

     

    try this.

    Rolling AVG Points last 6 matches = 
    CALCULATE (
        AVERAGE ( 'Table'[Points] );
        TOPN (
            6;
            FILTER ( ALL ( 'Table'[Date] ); 'Table'[Date] <= MAX ( 'Table'[Date] ) );
            'Table'[Date]; DESC
        )
    )

     

    You may download my PBIX file from here.
    Hope this helps.

     

    Regards,

    Marcus

    Dortmund - Germany
    If I answered your question, please mark my post as solution, this will also help others.
    Please give Kudos for support.

    • michaeldonnelly's avatar
      michaeldonnelly
      Frequent Visitor

      On your file it seems to work perfectly, when I have copied the measure as the table names are all the same, I am getting a different result, which is baffling, I have attached my file

       

      Link 

      • mwegener's avatar
        mwegener
        Icon for Most Valuable Professional rankMost Valuable Professional

        Hi michaeldonnelly ,

         

        I don't have access to your link.
        Please check the authorization.
        It should be "Anyone with this link".