<?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 Month plus month average in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Month-plus-month-average/m-p/4036962#M160017</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table in Power Bi with all our staff, and costings. The tsblr has a "Date" column, as well as "Year", "Month" &amp;amp; "Quarter" and then&amp;nbsp; a "Cost" column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been looking for a way to calculate the average "Cost" in a specific way but unable to find an answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need, is to sum for each month (for monthly cost totals)&lt;/P&gt;&lt;P&gt;Then&lt;/P&gt;&lt;P&gt;Average between month 1 &amp;amp; 2,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Average between month 2 &amp;amp; 3&amp;nbsp;&lt;/P&gt;&lt;P&gt;And so on....&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then sum all the above average and divide by 12.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;Any help is much appreciated &lt;span class="lia-unicode-emoji" title=":clapping_hands:"&gt;👏&lt;/span&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jul 2024 11:04:19 GMT</pubDate>
    <dc:creator>TsW08</dc:creator>
    <dc:date>2024-07-11T11:04:19Z</dc:date>
    <item>
      <title>Month plus month average</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Month-plus-month-average/m-p/4036962#M160017</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table in Power Bi with all our staff, and costings. The tsblr has a "Date" column, as well as "Year", "Month" &amp;amp; "Quarter" and then&amp;nbsp; a "Cost" column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been looking for a way to calculate the average "Cost" in a specific way but unable to find an answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need, is to sum for each month (for monthly cost totals)&lt;/P&gt;&lt;P&gt;Then&lt;/P&gt;&lt;P&gt;Average between month 1 &amp;amp; 2,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Average between month 2 &amp;amp; 3&amp;nbsp;&lt;/P&gt;&lt;P&gt;And so on....&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then sum all the above average and divide by 12.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;Any help is much appreciated &lt;span class="lia-unicode-emoji" title=":clapping_hands:"&gt;👏&lt;/span&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 11:04:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Month-plus-month-average/m-p/4036962#M160017</guid>
      <dc:creator>TsW08</dc:creator>
      <dc:date>2024-07-11T11:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: Month plus month average</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Month-plus-month-average/m-p/4037071#M160026</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="773835" data-lia-user-login="TsW08" class="lia-mention lia-mention-user"&gt;TsW08&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&amp;nbsp;Create a calculated column for monthly totals&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MonthlyTotal = &lt;BR /&gt;CALCULATE(&lt;BR /&gt;SUM(StaffCostings[Cost]),&lt;BR /&gt;ALLEXCEPT(StaffCostings, StaffCostings[Year], StaffCostings[Month])&lt;BR /&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a calculated column for the moving average between consecutive months:&lt;/P&gt;
&lt;P&gt;DAX&lt;BR /&gt;MovingAverage = &lt;BR /&gt;VAR CurrentMonth = StaffCostings[Month]&lt;BR /&gt;VAR CurrentYear = StaffCostings[Year]&lt;BR /&gt;VAR PreviousMonth = IF(CurrentMonth = 1, 12, CurrentMonth - 1)&lt;BR /&gt;VAR PreviousYear = IF(CurrentMonth = 1, CurrentYear - 1, CurrentYear)&lt;BR /&gt;VAR PreviousMonthTotal = &lt;BR /&gt;CALCULATE(&lt;BR /&gt;SUM(StaffCostings[MonthlyTotal]),&lt;BR /&gt;StaffCostings[Year] = PreviousYear,&lt;BR /&gt;StaffCostings[Month] = PreviousMonth&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;IF(&lt;BR /&gt;ISBLANK(PreviousMonthTotal),&lt;BR /&gt;BLANK(),&lt;BR /&gt;(StaffCostings[MonthlyTotal] + PreviousMonthTotal) / 2&lt;BR /&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a measure to sum the moving averages and divide by 12&lt;/P&gt;
&lt;P&gt;DAX&lt;BR /&gt;FinalAverage = &lt;BR /&gt;VAR MovingAverages = &lt;BR /&gt;CALCULATETABLE(&lt;BR /&gt;VALUES(StaffCostings[MovingAverage]),&lt;BR /&gt;NOT(ISBLANK(StaffCostings[MovingAverage]))&lt;BR /&gt;)&lt;BR /&gt;VAR SumOfMovingAverages = SUMX(MovingAverages, [MovingAverage])&lt;BR /&gt;RETURN&lt;BR /&gt;SumOfMovingAverages / 12&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 12:01:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Month-plus-month-average/m-p/4037071#M160026</guid>
      <dc:creator>bhanu_gautam</dc:creator>
      <dc:date>2024-07-11T12:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Month plus month average</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Month-plus-month-average/m-p/4037196#M160032</link>
      <description>&lt;P&gt; Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="625922" data-lia-user-login="bhanu_gautam" class="lia-mention lia-mention-user"&gt;bhanu_gautam&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the fast response. The formula seems to return an empty column (see images below). Does this look correct?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 13:29:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Month-plus-month-average/m-p/4037196#M160032</guid>
      <dc:creator>TsW08</dc:creator>
      <dc:date>2024-07-11T13:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Month plus month average</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Month-plus-month-average/m-p/4038850#M160121</link>
      <description>&lt;P&gt;Thanks for your prompt reply!&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="625922" data-lia-user-login="bhanu_gautam" class="lia-mention lia-mention-user"&gt;bhanu_gautam&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="773835" data-lia-user-login="TsW08" class="lia-mention lia-mention-user"&gt;TsW08&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Based on your needs, I have created the following table.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Then you can try the following dax to get "total cost", "average between two months", "average divide by 12".&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Total = 
VAR _month = SELECTEDVALUE('Table'[Month])
VAR _year = SELECTEDVALUE('Table'[Year])

RETURN
CALCULATE(SUM('Table'[Cost]),FILTER(ALL('Table'),'Table'[Year]=_year &amp;amp;&amp;amp; 'Table'[Month]=_month))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Average = 
VAR _month = SELECTEDVALUE('Table'[Month])
VAR _year = SELECTEDVALUE('Table'[Year])
VAR _current = CALCULATE([Total],FILTER(ALL('Table'),'Table'[Year] = _year &amp;amp;&amp;amp; 'Table'[Month] = _month))
VAR _previous = CALCULATE([Total],FILTER(ALL('Table'),'Table'[Year] = _year &amp;amp;&amp;amp; 'Table'[Month] = _month - 1))

RETURN IF(_previous = BLANK(),[Total],(_current + _previous)/2)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;average and divide by 12 = 
var _year = SELECTEDVALUE('Table'[Year])
RETURN
SUMX(FILTER(ALL('Table'),'Table'[Year]=_year),'Table'[Average])/12&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Jayleny&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2024 08:01:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Month-plus-month-average/m-p/4038850#M160121</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-12T08:01:24Z</dc:date>
    </item>
  </channel>
</rss>

