Share via

Power Query - How do you create a Rolling 12 month average?

PQ 20 Reputation points
2025-10-15T04:17:38.1866667+00:00

How do you create a rolling 12 month average in Power Query? For example, I am taking the last 12 months of data and creating a formula to get the average (i.e. the sales revenue x # of days in the month). See attached screenshot for details.

Every month I have to grab the most recent last 12 months of data, so I'm updating all my formulas manually across the 12 month period. How do I automate this in M language in Power query so it just automatically rolls and gives me the data in a new column?

Microsoft 365 and Office | Excel | For business | Windows

Answer accepted by question author

Kai-Ex 1,480 Reputation points Microsoft External Staff Moderator
2025-10-15T05:37:35.3433333+00:00

Dear @PQ,

Thank you for posting your question in the Microsoft Q&A forum.  

Based on my environment test and my understanding, please follow the steps below to prepare and transform your data effectively:  Move your source data into the designated location or file where you will perform the transformation.  Load the data into Power Query by selecting Data > Get Data > From Table/Range Your dataset may contain preliminary rows before the actual header row. Ensure that the row containing month names and key indicators (Sept 2024 Av, 30, 109,000.00) is promoted as the header. 

Home > Use First Row as Headers. If necessary, use Remove Rows to keep only the three essential rows (Month/Indicator, Days, Revenue) before applying Transpose. 

In Power Query Editor, go to Add Column > Custom Column and enter the following formula: 

= Table.AddColumn( 
    #"Changed Type1", 
    "Rolling 12 Month Avg", 
    (CurrentRow) => 
        let 
            // 1. Calculate the 'Monthly Value' for the current table 
            MonthlyValuesTable = Table.AddColumn( 
                #"Changed Type1", 
                "Monthly Value", 
                each [#"109000"] * [#"30"], 
                type number 
            ), 
            // 2. Filter the table to include the 12 months before or including the current row's date 
            CurrentDate = CurrentRow[Sept 2024], 
            FilterDate = Date.AddMonths(CurrentDate, -11), 
            // 3. Select the 'Monthly Value' column from the filtered rows 
            RollingValues = Table.SelectRows( 
                MonthlyValuesTable, 
                each [Sept 2024] >= FilterDate and [Sept 2024] <= CurrentDate 
            )[Monthly Value] 
        in 
            // 4. Calculate the average of the rolling values 
            List.Average(RollingValues) 
) 

User's image

Note: Adjust column references in the formula to match your actual dataset structure. 

If there’s anything I may have misunderstood, I would truly appreciate it if you could provide a bit more detail to help me better understand your needs.  Also, if you’re stuck on anything or find something unclear, please feel free to reply so I can guide you further. 


Looking forward to your response!  If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 

Was this answer helpful?


2 additional answers

Sort by: Most helpful
  1. IlirU 2,491 Reputation points Volunteer Moderator
    2025-10-16T08:21:57.1633333+00:00

    User's image

    Hi,

    Try below formula in cell M4:

    =LET(d, A3:L3, SUM(MAP(d, A4:L4, PRODUCT)) / SUM(d))

    Hope this helps.

    Was this answer helpful?

    0 comments No comments

  2. Ashish Mathur 101.8K Reputation points Volunteer Moderator
    2025-10-15T23:44:47.82+00:00

    Hi,

    With the way your data is arranged, writing an Excel formula would be much simpler. In cell H4, enter this formula

    =LET(a,L3:XLOOKUP(EDATE(M2,-11),A2:L2,A3:L3),SUM((L4:XLOOKUP(EDATE(M2,-11),A2:L2,A4:L4))*(a))/SUM(a))

    The headings in row 2 are actuals date such as 01/09/2024, 01/10/2024 etc. They are formatted as mmm-yy.

    Hope this helps.

    User's image

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.