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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
cld32650
Frequent Visitor

Moving Average of Multiple Series

I would like to calculate the moving average of multiple series data as a measure. The data is monthly spanning 40+ years. 

 

The columns of data are "Scenario", "Year", "Series", and "Value". A slicer filters the table for "Scenario", but no filtering is performed on series because I want to visualize the moving average of each series in one figure. Table below shows how data is currently formatted (Aggregated to annual for simplicity).

ScenarioYearSeriesValue
120201100
120211106
120221109
12020298
12021299
120222105

Ignoring the edge cases in this scenario, the 3 year moving average in 2021 for series 1 would return 105; the 3yr moving average in 2021 for series 2 would return 100.67.

The data will be displayed on a scatter plot as a tooltip, where the scatter plot displays other data for every year, and series, filtered by a scenario slicer. 

 

To get started I have tried to move the calculation to a calculated column, but the calculation is simply returning the same number from the Value column on the same row (almost like a copy/paste to another column).

Below is the code I have tried. Any suggestions to get the calculation correct would be greatly appreciated - keep in mind please the end goal is to move all of this to a measure.

 

Var PeriodToUse = 
    Filter(
        All(testtable[Year]),
        And(
            testtable[Year] < 2030,
            testtable[Year] > 2026
        )
    )
Var Result =
    Calculate(
        AVERAGEX('testtable',[Value]),
        PeriodToUse
    )

RETURN
Result

 

 

1 ACCEPTED SOLUTION
suparnababu8
Super User
Super User

Hello @cld32650 

 

suparnababu8_0-1739494919197.png

I hope you are looking for this. Attched pbix file here for your reference.

 

 

Thanks!

 

 

View solution in original post

5 REPLIES 5
suparnababu8
Super User
Super User

Hello @cld32650 

 

suparnababu8_0-1739494919197.png

I hope you are looking for this. Attched pbix file here for your reference.

 

 

Thanks!

 

 

Thank you for the worked example. For others that are interested, the code within the file is copied below -  note, this creates a trailing moving average, whereas the question is about a centered moving average. An additional variable to define the end year was the only needed adjustment to finalize the code.

 

Moving Average 3 Years = 
VAR CurrentYear = MAX('MovingAvgExample'[Year])
VAR StartYear = CurrentYear - 2
RETURN
CALCULATE(AVERAGEX(
        FILTER(ALL('MovingAvgExample'),
            'MovingAvgExample'[Year] >= StartYear && 'MovingAvgExample'[Year] <= CurrentYear &&
            'MovingAvgExample'[Series] = MAX('MovingAvgExample'[Series]) && 'MovingAvgExample'[Scenario] = MAX('MovingAvgExample'[Scenario])),'MovingAvgExample'[Value]  ))

 

Anonymous
Not applicable

Hi,@cld32650 
We are delighted that you have found a solution and are willing to share it.

 

Accepting your post as the solution is incredibly helpful to our community, as it enables members with similar issues to find answers more quickly.

 

Thank you for your valuable contribution to the community, and we wish you all the best in your work.

 

Best Regards,

Leroy Lu

ryan_mayu
Super User
Super User

you can try this

 

Column = CALCULATE(average('Table'[Value]),ALLEXCEPT('Table','Table'[Scenario],'Table'[Series]))
 
11.PNG
or 
 
Measure = CALCULATE(average('Table'[Value]),ALLEXCEPT('Table','Table'[Scenario],'Table'[Series]))
12.PNG
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you for the response. I have not verified this solution because another workable response was provided earlier.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.