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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculate Exponential Smoothing Forecast on Query Editor

Hi all, I have been searching high and low for a way to populate a column of forecasted values using DAX. Other than forecasting by moving average, I have not been able to find any methods to perform exponential smoothing forecasting using DAX.

 

I am currently exploring ways to do so on Query Editor. Assume I have the following simple dataset. How do I populate a column containing the forecasted numbers?

 

Here is the PBIX file:

https://www.dropbox.com/s/wc30mt5kron382t/Inventory%20Forecasting.pbix?dl=0

 

Thank you!

5 REPLIES 5
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

 

The Exponential Smoothing is a little complicated. There could be a solution here by R.

# 'dataset' holds the input data for this script
temp <- dataset
temp$Date <- as.Date(temp$Date, '%Y-%m-%d')
es <- c()
minDate <- temp$Date[1]
ds_length <- length(temp$Date)
for (index in c(1:ds_length)) {
    if (temp[index,1] == minDate) {
        st <- temp[index, 3]
    }
    else {
        st <- 0.2 * temp[index, 3] + (1 - 0.2) * es[index - 1]
    }
    es[index] <- st
}
temp$es <- es

Calculate_Exponential_Smoothing_Forecast_on_Query_Editor

 

Best Regards,

Dale

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

Could you please clarify how to make this code reusable to just replace parameters (Date, Value)?

when I executed this code I received an error
(Error in if (temp[index, 1] == minDate) { :
  missing value where TRUE/FALSE needed
Execution halted
)

Anonymous
Not applicable

Also, @v-jiascu-msft how do I forecast for the following year? Could you share the code for me (I don't know R language yet)? The calculation you provided only allows for forecasting in the same period.

Anonymous
Not applicable

anyone?

Anonymous
Not applicable

Thank you @v-jiascu-msft! Could you suggest me some resources to learning R on Power BI?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.