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
yj1111
Helper I
Helper I

Moving Average Calculation for Forecasting

Dear all,

 

I would like to use Moving Average of actuals in the same period last year to predict my actuals in the rest of the year. 

I use line and stacked column chart to show the values. 

X-axis: Month Nr of year 2024 (only 2024 is selected)

Y-axis: 1) Actual costs from month 1-6 (column), 2) Forecast costs from 7-12 (line)

 

The Dax function I use for moving average calculation: 

Actuals MA = AVERAGEX(DATESINPERIOD(Dates[Date],LASTDATE(Dates[Date]),-30,DAY],[ActualCosts])

Actuals Forecast = IF(ISBLANK([ActualCosts], CALCULATE([Actuals MA], SAMEPERIODLASTYEAR(Dates[Date])))

 

If I use Dates[Date] as X-axis, everything will work, however, the Actuals Forecast does not sum up on month level. How can I adjust my dax functions? (MovingAverage Dax Function is not availble in my PBI version)

 

Thanks in advance!

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,@yj1111 .I am glad to help you.
According to your description, you have correctly calculated the correct result from the measure, but it is not displaying correctly on the line/bar chart in months.
If my understanding is correct, you can refer to my test below
Here is my test data:

vjtianmsft_0-1721019081729.pngvjtianmsft_1-1721019088358.png

Here are two of your original measures

Actuals Forecast = 
IF(
    ISBLANK([ActualCosts]), 
    CALCULATE(
        [Actuals MA], 
        SAMEPERIODLASTYEAR(Dates[Date])
    )
)
Actuals MA = 
AVERAGEX (
    DATESINPERIOD ( Dates[Date], LASTDATE ( Dates[Date] ), -30, DAY ),
    [ActualCosts]
)

To accommodate the fact that the Actuals MA uses a measure [ActualCosts], you don't give the exact code in your question.
So I modeled a simple measure (the column values in the table is [ActualCost])

vjtianmsft_2-1721019184948.png
Here is my solution idea:
I recreated a new column YearMonth
and used that column to replace the Date column that was originally displayed in visual
Wrote a new measure.
Aggregate your original end result for each day into months by month.
like this:

M_finalresult = 
VAR _yearMonth=MAX('Dates'[YearMonth])
RETURN
SUMX(
        FILTER(
            Dates, 
            Dates[YearMonth] = _yearMonth
        ), 
        [Actuals Forecast]
    )

vjtianmsft_3-1721019248324.png

vjtianmsft_4-1721019263265.png

The fields displayed on the x-axis and y-axis of the discounted graph are as follows.

vjtianmsft_5-1721019282565.png

Note that my test results may not be suitable for your real data, so you need to modify the code I provided or create a new code according to your actual situation, because due to the different computing environment will affect the final results of the measure.
I hope my test results can bring you good ideas.

If you can provide a pbix file that doesn't contain sensitive data (which you can share with everyone via OneDrive), that will help solve your problem.

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,

Carson Jian,

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



View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi,@yj1111 .I am glad to help you.
According to your description, you have correctly calculated the correct result from the measure, but it is not displaying correctly on the line/bar chart in months.
If my understanding is correct, you can refer to my test below
Here is my test data:

vjtianmsft_0-1721019081729.pngvjtianmsft_1-1721019088358.png

Here are two of your original measures

Actuals Forecast = 
IF(
    ISBLANK([ActualCosts]), 
    CALCULATE(
        [Actuals MA], 
        SAMEPERIODLASTYEAR(Dates[Date])
    )
)
Actuals MA = 
AVERAGEX (
    DATESINPERIOD ( Dates[Date], LASTDATE ( Dates[Date] ), -30, DAY ),
    [ActualCosts]
)

To accommodate the fact that the Actuals MA uses a measure [ActualCosts], you don't give the exact code in your question.
So I modeled a simple measure (the column values in the table is [ActualCost])

vjtianmsft_2-1721019184948.png
Here is my solution idea:
I recreated a new column YearMonth
and used that column to replace the Date column that was originally displayed in visual
Wrote a new measure.
Aggregate your original end result for each day into months by month.
like this:

M_finalresult = 
VAR _yearMonth=MAX('Dates'[YearMonth])
RETURN
SUMX(
        FILTER(
            Dates, 
            Dates[YearMonth] = _yearMonth
        ), 
        [Actuals Forecast]
    )

vjtianmsft_3-1721019248324.png

vjtianmsft_4-1721019263265.png

The fields displayed on the x-axis and y-axis of the discounted graph are as follows.

vjtianmsft_5-1721019282565.png

Note that my test results may not be suitable for your real data, so you need to modify the code I provided or create a new code according to your actual situation, because due to the different computing environment will affect the final results of the measure.
I hope my test results can bring you good ideas.

If you can provide a pbix file that doesn't contain sensitive data (which you can share with everyone via OneDrive), that will help solve your problem.

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,

Carson Jian,

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



Helpful resources

Announcements
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.

June 2025 community update carousel

Fabric Community Update - June 2025

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