<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Moving Average Calculation for Forecasting in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-Average-Calculation-for-Forecasting/m-p/4040380#M160206</link>
    <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use line and stacked column chart to show the values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;X-axis: Month Nr of year 2024 (only 2024 is selected)&lt;/P&gt;&lt;P&gt;Y-axis: 1) Actual costs from month 1-6 (column), 2) Forecast costs from 7-12 (line)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Dax function I use for moving average calculation:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actuals MA = AVERAGEX(DATESINPERIOD(Dates[Date],LASTDATE(Dates[Date]),-30,DAY],[ActualCosts])&lt;/P&gt;&lt;P&gt;Actuals Forecast = IF(ISBLANK([ActualCosts], CALCULATE([Actuals MA], SAMEPERIODLASTYEAR(Dates[Date])))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I use&amp;nbsp;Dates[Date] as X-axis, everything will work, however,&amp;nbsp;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)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 13 Jul 2024 07:05:21 GMT</pubDate>
    <dc:creator>yj1111</dc:creator>
    <dc:date>2024-07-13T07:05:21Z</dc:date>
    <item>
      <title>Moving Average Calculation for Forecasting</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-Average-Calculation-for-Forecasting/m-p/4040380#M160206</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use line and stacked column chart to show the values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;X-axis: Month Nr of year 2024 (only 2024 is selected)&lt;/P&gt;&lt;P&gt;Y-axis: 1) Actual costs from month 1-6 (column), 2) Forecast costs from 7-12 (line)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Dax function I use for moving average calculation:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actuals MA = AVERAGEX(DATESINPERIOD(Dates[Date],LASTDATE(Dates[Date]),-30,DAY],[ActualCosts])&lt;/P&gt;&lt;P&gt;Actuals Forecast = IF(ISBLANK([ActualCosts], CALCULATE([Actuals MA], SAMEPERIODLASTYEAR(Dates[Date])))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I use&amp;nbsp;Dates[Date] as X-axis, everything will work, however,&amp;nbsp;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)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jul 2024 07:05:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-Average-Calculation-for-Forecasting/m-p/4040380#M160206</guid>
      <dc:creator>yj1111</dc:creator>
      <dc:date>2024-07-13T07:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: Moving Average Calculation for Forecasting</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-Average-Calculation-for-Forecasting/m-p/4041587#M160252</link>
      <description>&lt;P&gt;Hi,&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="469531" data-lia-user-login="yj1111" class="lia-mention lia-mention-user"&gt;yj1111&lt;/a&gt;&amp;nbsp;.I am glad to help you.&lt;BR /&gt;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.&lt;BR /&gt;If my understanding is correct, you can refer to my test below&lt;BR /&gt;Here is my test data:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Here are two of your original measures&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Actuals Forecast = 
IF(
    ISBLANK([ActualCosts]), 
    CALCULATE(
        [Actuals MA], 
        SAMEPERIODLASTYEAR(Dates[Date])
    )
)&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Actuals MA = 
AVERAGEX (
    DATESINPERIOD ( Dates[Date], LASTDATE ( Dates[Date] ), -30, DAY ),
    [ActualCosts]
)&lt;/LI-CODE&gt;
&lt;P&gt;To accommodate the fact that the Actuals MA uses a measure [ActualCosts], you don't give the exact code in your question.&lt;BR /&gt;So I modeled a simple measure (the column values in the table is [ActualCost])&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;BR /&gt;Here is my solution idea:&lt;BR /&gt;I recreated a new column YearMonth&lt;BR /&gt;and used that column to replace the Date column that was originally displayed in visual&lt;BR /&gt;Wrote a new measure.&lt;BR /&gt;Aggregate your original end result for each day into months by month.&lt;BR /&gt;like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;M_finalresult = 
VAR _yearMonth=MAX('Dates'[YearMonth])
RETURN
SUMX(
        FILTER(
            Dates, 
            Dates[YearMonth] = _yearMonth
        ), 
        [Actuals Forecast]
    )&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;The fields displayed on the x-axis and y-axis of the discounted graph are as follows.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;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.&lt;BR /&gt;I hope my test results can bring you good ideas.&lt;BR /&gt;&lt;BR /&gt;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.&lt;/P&gt;
&lt;P&gt;I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Carson Jian,&lt;/P&gt;
&lt;P&gt;If this post &lt;EM&gt;&lt;STRONG&gt;helps&lt;/STRONG&gt;&lt;/EM&gt;, then please consider &lt;EM&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/EM&gt; to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 04:56:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-Average-Calculation-for-Forecasting/m-p/4041587#M160252</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-15T04:56:31Z</dc:date>
    </item>
  </channel>
</rss>

