<?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: 12 Previous Months Sum for each month in the past from current month in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809212#M5127</link>
    <description>&lt;P&gt;Thanks for the reply there, but don't think this is giving me what I need.&amp;nbsp; What would be the Calendar FullDate?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do have a calendar table tho.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Oct 2019 17:01:26 GMT</pubDate>
    <dc:creator>Midway</dc:creator>
    <dc:date>2019-10-03T17:01:26Z</dc:date>
    <item>
      <title>12 Previous Months Sum for each month in the past from current month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/808423#M5089</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Been trying to get the DAX for this but no luck so far. Need some help on the following.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for each month, I'm trying to Sum the previous 12 months of data. Let's say for September 2019, I need to go back 12 months and sum the number of sales (Oct/2018 to Sept/2019). The same goes for the rest of the months in the past, for Aug/2019 should be&amp;nbsp; Sept/2018 to Aug/2019 and so on for the rest of the months in the past.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Midway&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 01:40:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/808423#M5089</guid>
      <dc:creator>Midway</dc:creator>
      <dc:date>2019-10-03T01:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: 12 Previous Months Sum for each month in the past from current month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/808451#M5090</link>
      <description>&lt;P&gt;here's some sample code i found online&lt;/P&gt;&lt;PRE&gt;Sales12M := CALCULATE (
    [Sales],
    DATESBETWEEN (
        Calendar[FullDate],
        NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( Calendar[FullDate] ) ) ),
        LASTDATE ( Calendar[FullDate] )
    )
)&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Oct 2019 02:39:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/808451#M5090</guid>
      <dc:creator>kentyler</dc:creator>
      <dc:date>2019-10-03T02:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: 12 Previous Months Sum for each month in the past from current month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809212#M5127</link>
      <description>&lt;P&gt;Thanks for the reply there, but don't think this is giving me what I need.&amp;nbsp; What would be the Calendar FullDate?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do have a calendar table tho.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 17:01:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809212#M5127</guid>
      <dc:creator>Midway</dc:creator>
      <dc:date>2019-10-03T17:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: 12 Previous Months Sum for each month in the past from current month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809214#M5128</link>
      <description>&lt;P&gt;That would be the name of the field in your calendar table that holds the date.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 17:05:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809214#M5128</guid>
      <dc:creator>kentyler</dc:creator>
      <dc:date>2019-10-03T17:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: 12 Previous Months Sum for each month in the past from current month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809226#M5130</link>
      <description>&lt;P&gt;That's what I thought, but still not showing the right numbers. This is suming the last 12 months from current month (October 2019 to October 2018) but this is just repeating the same numbers for the other dates. Like for example Sep-2019 should sum from Sept-2019 to Sept 2018 and so forth.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 17:34:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809226#M5130</guid>
      <dc:creator>Midway</dc:creator>
      <dc:date>2019-10-03T17:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: 12 Previous Months Sum for each month in the past from current month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809234#M5132</link>
      <description>&lt;P&gt;Can you make a sample pofwer bi file available ?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 17:33:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809234#M5132</guid>
      <dc:creator>kentyler</dc:creator>
      <dc:date>2019-10-03T17:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: 12 Previous Months Sum for each month in the past from current month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809245#M5133</link>
      <description>&lt;P&gt;This is an example of what I'm trying to accomplish. The previous 12 months sum column should sum from current month 12 months in the pat. For the previous month, it should sum from Septeber 2019 to past 12 months and so on for the rest of the months in the past. Let me know if I'm making any sense here please.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Sale Date&lt;/TD&gt;&lt;TD&gt;Sales&lt;/TD&gt;&lt;TD&gt;Previous 12 months sum&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Jun-18&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Jul-18&lt;/TD&gt;&lt;TD&gt;18&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Aug-18&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sep-18&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Oct-18&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;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gt;&lt;TR&gt;&lt;TD&gt;Oct-19&lt;/TD&gt;&lt;TD&gt;60&lt;/TD&gt;&lt;TD&gt;441&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 03 Oct 2019 17:46:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809245#M5133</guid>
      <dc:creator>Midway</dc:creator>
      <dc:date>2019-10-03T17:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: 12 Previous Months Sum for each month in the past from current month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809331#M5142</link>
      <description>&lt;P&gt;I added some months to make it easier for me to debug the measure&lt;/P&gt;&lt;P&gt;&lt;img /&gt;here is the measure:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Prev 12 Months Sales = &lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;VAR start_date = max('Sales'[Sales Date])&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;var start_date_for_sales_month = datevalue(month(start_date) &amp;amp; "/1/" &amp;amp; year(start_date))&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;var end_date_for_month = edate(start_date_for_sales_month,-12)&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;var min_date = calculate(min(Sales[Sales Date]) ,All())&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;var min_date_month = datevalue(month(min_date) &amp;amp; "/1/" &amp;amp; year(min_date))&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;var show_amount = min_date_month &amp;lt;= end_date_for_month&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;var amount = calculate(sum(sales[sales amount]),sales[sales date] &amp;lt;= start_date_for_sales_month, sales[sales date] &amp;lt;= start_date)&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;return if(show_amount,amount)&lt;/STRONG&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;There might be easier ways.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I started by getting the first day of the month for the row.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Then i used edate to get a date 12 months in the past&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I calculated the minimum date in the data set&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;then i checked to see if the month 12 months in the past was greater than the minimum date in the dataset and less than the month in the current row&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if it was, then i used calculate to add up the sales for the month.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;DAX has some great functions to simplify calculating periods, and dates in periods, but i could not figure out how to use them when the month was represented by "any date in the month"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Hope this helps&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Ken Tyler&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 03 Oct 2019 19:51:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/12-Previous-Months-Sum-for-each-month-in-the-past-from-current/m-p/809331#M5142</guid>
      <dc:creator>kentyler</dc:creator>
      <dc:date>2019-10-03T19:51:12Z</dc:date>
    </item>
  </channel>
</rss>

