Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin 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.
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:
Solved! Go to Solution.
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])
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
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:
Thank you very much for the help
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])
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