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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Jo5hua22
Helper I
Helper I

Calculate moving average of continuous or overlapping values

Hi,

 

I would like to calculate the Moving Average of 3 continuous or overlapping values. 

 

An example is given in the below screeshot

 

I know it has to deal with sorting the dates according to index value, then using only the respective batches and finally calculaing the moving average of those batches that are sorted according to the dates.

 

Can you please help me out? 

Example:

Jo5hua22_0-1624460081125.png

 

 

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @Jo5hua22 ,

 

You need to create a index column in your table and rank your table by the index column and date column:

 

rankvalue = RANKX(FILTER('Table','Table'[Batch Number] = EARLIER('Table'[Batch Number])&&NOT(ISBLANK('Table'[Date]))),VALUE('Table'[Date])+'Table'[Index]/100,,ASC)

 

Then you can use the following calculated column to compute the moving average:

 

moving average = VAR A = 'Table'[rankvalue] RETURN  IF('Table'[rankvalue]>=3,AVERAGEX(FILTER(ALL('Table'),'Table'[Batch Number] = EARLIER('Table'[Batch Number])&& 'Table'[rankvalue]<=A&&'Table'[rankvalue]>A-3),'Table'[Value]),'Table'[Value])

 

Capture39.PNG

 

Please refer to the pbix file.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

 

 

View solution in original post

3 REPLIES 3
Jo5hua22
Helper I
Helper I

Hi @v-deddai1-msft ,

 

In addition to your solution, I need to rank the table based on another column if there are more than 1 value of the same batch number are in the same date. Can you let me know how to do it?

Please note that the required calculation should cover your previous solution wherein here we sort the batches  and now if there are more than 1 value produced on the same date then loop number has to be taken into consideration.

Example:

Jo5hua22_0-1628449098921.png

 

Jo5hua22
Helper I
Helper I

Thank you very much for the help

v-deddai1-msft
Community Support
Community Support

Hi @Jo5hua22 ,

 

You need to create a index column in your table and rank your table by the index column and date column:

 

rankvalue = RANKX(FILTER('Table','Table'[Batch Number] = EARLIER('Table'[Batch Number])&&NOT(ISBLANK('Table'[Date]))),VALUE('Table'[Date])+'Table'[Index]/100,,ASC)

 

Then you can use the following calculated column to compute the moving average:

 

moving average = VAR A = 'Table'[rankvalue] RETURN  IF('Table'[rankvalue]>=3,AVERAGEX(FILTER(ALL('Table'),'Table'[Batch Number] = EARLIER('Table'[Batch Number])&& 'Table'[rankvalue]<=A&&'Table'[rankvalue]>A-3),'Table'[Value]),'Table'[Value])

 

Capture39.PNG

 

Please refer to the pbix file.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

 

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.