<?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 Re: Moving average / moving variance in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1033328#M13655</link>
    <description>&lt;P&gt;This looks like a measure totals problem. Very common. See my post about it here: &lt;A href="https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376" target="_blank"&gt;https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:&lt;BR /&gt;&lt;A href="https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907" target="_blank"&gt;https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Apr 2020 20:24:13 GMT</pubDate>
    <dc:creator>Greg_Deckler</dc:creator>
    <dc:date>2020-04-17T20:24:13Z</dc:date>
    <item>
      <title>Moving average / moving variance</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1033291#M13654</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I want to calculate a moving average of my measure over the last 12 months.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use the following DAX formula so far, which works, as long as my time granularity level is the month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;AVG_Produktion =
CALCULATE (
    [PRODUKTION];
    DATESINPERIOD (
        Datumstabelle[Date];
        LASTDATE ( Datumstabelle[Date] );
        -12;
        MONTH
    )
) / 12
    * DIVIDE ( [PRODUKTION]; [PRODUKTION] )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The results look like this:&lt;/P&gt;&lt;P&gt;The value for Jan 2022 is correct (average of the months Feb 2021 - Jan 2022), however the value for the whole year 2022 is obviously not correct - I'm actually not completely sure, where this value comes from.&lt;BR /&gt;What I want to see here is the sum of all the MA values for 2022, so that I can compare it to the actual yearly production.&lt;BR /&gt;Similarly, if I go down on the date level, I want to know, what the average daily production was in the last 12 months.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I assume, there should be some kind of an elegant solution using the average or averagex function.&lt;/P&gt;&lt;P&gt;The other question is how to compute a moving variance for the same time periods, ideally without having to calculate the variance formula by hand, bur rather using the VARX.P function.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 19:57:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1033291#M13654</guid>
      <dc:creator>IMett</dc:creator>
      <dc:date>2020-04-17T19:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Moving average / moving variance</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1033328#M13655</link>
      <description>&lt;P&gt;This looks like a measure totals problem. Very common. See my post about it here: &lt;A href="https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376" target="_blank"&gt;https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:&lt;BR /&gt;&lt;A href="https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907" target="_blank"&gt;https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 20:24:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1033328#M13655</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-04-17T20:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Moving average / moving variance</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1034225#M13691</link>
      <description>&lt;P&gt;Hi Greg,&lt;BR /&gt;Thanks for your answer, but I guess this is not the problem in this case, though it may seem so.&lt;BR /&gt;&lt;BR /&gt;If I just choose the year as my dimension, the value still remains the same, although there is no 'Total' lines involved.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sat, 18 Apr 2020 20:54:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1034225#M13691</guid>
      <dc:creator>IMett</dc:creator>
      <dc:date>2020-04-18T20:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Moving average / moving variance</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1034305#M13695</link>
      <description>&lt;P&gt;402.382 / 12 = 33.532.&lt;BR /&gt;&lt;BR /&gt;The calculation is correct.&lt;BR /&gt;&lt;BR /&gt;The Gesamt is correct as well according to the formula and to what one would expect. That's because it's not just an average but a 12-month monthly moving average.&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 23:33:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1034305#M13695</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-18T23:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Moving average / moving variance</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1039774#M13906</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;maybe the term "moving average" is misleading or even wrong here. I'll try to illustrate what I want to have with a simple Excel example:&lt;/P&gt;&lt;P&gt;Imagine I have raw data per month. The 12M-moving average for January 2020 (=C14) is AVERAGE(B2:B13).&amp;nbsp; [or maybe Average(B3:B14, if you take the new value into the timeframe, there are varying definitions I guess]&lt;BR /&gt;With this formula, I can calculate the moving average for every month after the 12th.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;Now as long as I&amp;nbsp;&lt;STRONG&gt;display&amp;nbsp;&lt;/STRONG&gt;this measure on the month level, everything is fine, I can simply display the calculated values without any further aggregation.&lt;BR /&gt;But if I choose to aggregate on the year level (or quarter, whatever), then I have to take the SUM of all the values in column C, not their average!&lt;BR /&gt;If I create a Pivot Table in Excel, this is exactly what happens. But I don't know how to achieve the same behaviour in PowerBI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 21 Apr 2020 16:12:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1039774#M13906</guid>
      <dc:creator>IMett</dc:creator>
      <dc:date>2020-04-21T16:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: Moving average / moving variance</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1040123#M13918</link>
      <description>&lt;P&gt;You are mixing 2 different measures. One is the 12-month average and the other is the sum of the 12-month averages. If you want to have these 2 morphed into one... then you'll need to write a SWITCH which will select the measure based on what time period is in scope.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually... on reflection, you can do something simpler: you can write a measure that will sum up the averages over the currently visible pieces of time. If you never go below the month level, then it's even easier. Hide the individual dates so that they can't be selected, leave only pieces of time from the month up and write:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sumx(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; VALUES ( Calendar[YearMonth] ),&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; [12M Average]&lt;/P&gt;
&lt;P&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will give you what you want.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Best&lt;BR /&gt;D&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 19:33:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1040123#M13918</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-21T19:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Moving average / moving variance</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1043479#M14029</link>
      <description>&lt;P&gt;That looks good, thank you!&lt;BR /&gt;&lt;BR /&gt;Although it didn't solve my intiial question on how to calculate the moving variance, accordingly, without having to write the variance&amp;nbsp;formula explicitly. I hoped to find a way to calculate the&amp;nbsp;desired moving average&amp;nbsp;by using the function Averagex and adapt the filter settings to a different measure with the VARX.P function.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 07:38:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Moving-average-moving-variance/m-p/1043479#M14029</guid>
      <dc:creator>IMett</dc:creator>
      <dc:date>2020-04-23T07:38:46Z</dc:date>
    </item>
  </channel>
</rss>

