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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
BRV
Regular Visitor

Create forecast using moving average of recent actuals

I want to create a forecast of sales using the average of actual sales over the past several weeks as the forecast. See below for an example of the data I have and what I'm trying to acccomplish. I have measures for Daily Sales, Sales Lagged 1 Week, and the average of the first 2 measures. What I want to create is a measure that yields the results in the Forecast column. Each value in this column is the most recent value for that day (Mon, Tues, Wed, etc.) from the Average column. I want to extend the forecast column through the last date in the my Calendar table which is the end of the current year. Any help will be greatly appreciated.

 

Forecast.jpg

 

 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

All measures are in the attached pbix file.

 

Picture1.png

 

 
Daily Sales: =
SUM( Sales[Sales] )
 
Sales Lagged one week: =
VAR currentdate =
MAX ( Dates[Date] )
RETURN
IF (
NOT ISBLANK ( [Daily Sales:] ),
CALCULATE ( [Daily Sales:], Dates[Date] = currentdate - 7 )
)
 
Average: =
VAR salestable =
ADDCOLUMNS ( VALUES ( Dates[Date] ), "@value", [Daily Sales:] )
VAR laggedtable =
ADDCOLUMNS ( VALUES ( Dates[Date] ), "@value", [Sales Lagged one week:] )
VAR uniontable =
UNION ( salestable, laggedtable )
RETURN
IF (
[Daily Sales:] && [Sales Lagged one week:],
AVERAGEX ( uniontable, [@value] )
)
 
Forecast: =
VAR currentday =
WEEKDAY ( MAX ( Dates[Date] ) )
VAR lastsalesdate =
CALCULATE ( MAX ( Sales[Date] ), REMOVEFILTERS () )
VAR newtable =
FILTER (
SELECTCOLUMNS (
ADDCOLUMNS (
DATESINPERIOD ( Dates[Date], lastsalesdate, -7, DAY ),
"@avg", [Average:]
),
"@weekday", WEEKDAY ( Dates[Date] ),
"@average", [@avg]
),
[@weekday] = currentday
)
RETURN
IF ( MAX ( Dates[Date] ) > lastsalesdate && HASONEVALUE(Dates[Date]), MAXX ( newtable, [@average] ) )
 
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

This was extremely helpful - exactly what I was looking for. Thank you for the quick response.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

All measures are in the attached pbix file.

 

Picture1.png

 

 
Daily Sales: =
SUM( Sales[Sales] )
 
Sales Lagged one week: =
VAR currentdate =
MAX ( Dates[Date] )
RETURN
IF (
NOT ISBLANK ( [Daily Sales:] ),
CALCULATE ( [Daily Sales:], Dates[Date] = currentdate - 7 )
)
 
Average: =
VAR salestable =
ADDCOLUMNS ( VALUES ( Dates[Date] ), "@value", [Daily Sales:] )
VAR laggedtable =
ADDCOLUMNS ( VALUES ( Dates[Date] ), "@value", [Sales Lagged one week:] )
VAR uniontable =
UNION ( salestable, laggedtable )
RETURN
IF (
[Daily Sales:] && [Sales Lagged one week:],
AVERAGEX ( uniontable, [@value] )
)
 
Forecast: =
VAR currentday =
WEEKDAY ( MAX ( Dates[Date] ) )
VAR lastsalesdate =
CALCULATE ( MAX ( Sales[Date] ), REMOVEFILTERS () )
VAR newtable =
FILTER (
SELECTCOLUMNS (
ADDCOLUMNS (
DATESINPERIOD ( Dates[Date], lastsalesdate, -7, DAY ),
"@avg", [Average:]
),
"@weekday", WEEKDAY ( Dates[Date] ),
"@average", [@avg]
),
[@weekday] = currentday
)
RETURN
IF ( MAX ( Dates[Date] ) > lastsalesdate && HASONEVALUE(Dates[Date]), MAXX ( newtable, [@average] ) )
 
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

This was extremely helpful - exactly what I was looking for. Thank you for the quick response.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.