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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Moving Average using Last and Next 3 months

I'm trying to calculate the moving average which looks at data for both the last 3 months and next 3 months.

 

Table of example data is below and the values i need are in column 3 (highlighted green). As an example for August 2016, the calculation would be to add the values of Column 2 for May, June, July, August, September, October and November and divide by 7 giving   43,665.04

 

Example Data

 

month of Notification DateAvg. Total IncomeMoving Average of Avg. Total Income
January 201617,710.4139,391.21
February 20168,289.1251,280.18
March 201669,765.3553,912.75
April 201661,799.9547,576.68
May 201698,836.0949,924.10
June 201667,075.5656,002.75
July 20169,560.2551,980.03
August 201634,142.3543,665.04
September 201650,839.6842,494.24
October 201641,606.3446,021.59
November 20163,594.9951,944.28
December 201690,640.5047,066.81

 

I currently am using the following calculation for moving averages but it only looks at the past  6 months:

 

_6m moving Total Income Average =
VAR period = 6
VAR the_first_date =
CALCULATE ( FIRSTDATE ( DateTable[Date] ), ALLSELECTED ( DateTable[Date] ))
VAR last_date =
LASTDATE ( DateTable[Date] )
VAR sum_in_period =
CALCULATE (
SUM ( Tabl1[totalIncome] ), DATESINPERIOD ( DateTable[Date], last_date, - period, MONTH ))
RETURN
IF ( last_date - the_first_date >= period -1 , sum_in_period / period )
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try measure like this with date table

 

Rolling 3 before 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAXX('Date',dateadd('Date'[Date],-3,month)),7,MONTH))/7

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@amitchandak  thanks i had to play around with the number of months to subtract but otherwise worked great

amitchandak
Super User
Super User

@Anonymous , Try measure like this with date table

 

Rolling 3 before 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAXX('Date',dateadd('Date'[Date],-3,month)),7,MONTH))/7

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.