<?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: To calculate previous month of sales in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2619386#M76232</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="76400" data-lia-user-login="pmadam" class="lia-mention lia-mention-user"&gt;pmadam&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your statement, I suggest you to combine [Year] and [&lt;SPAN&gt;Time.Month&lt;/SPAN&gt;] into one column as a key column in your calculation. Using two columns&amp;nbsp;[Year] and [&lt;SPAN&gt;Time.Month&lt;/SPAN&gt;] will make your calculation complex. Thiis new column should be in number type. Note:&amp;nbsp;&amp;nbsp;[Year] and [&lt;SPAN&gt;Time.Month&lt;/SPAN&gt;] should be in number type as well.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;YearMonth = [Year]*100 + [Time.Month]&lt;/LI-CODE&gt;
&lt;P&gt;Measure:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;PM Book RR1 =
VAR _PREVIOUS_YEARMONTH =
    MAXX (
        FILTER (
            ALL ( 'Sales vs Inv' ),
            'Sales vs Inv'[YearMonth] &amp;lt; MAX ( 'Sales vs Inv'[YearMonth] )
        ),
        'Sales vs Inv'[YearMonth]
    )
RETURN
    CALCULATE (
        SUM ( 'Sales vs Inv'[Book RR] ),
        FILTER (
            ALL ( 'Sales vs Inv' ),
            'Sales vs Inv'[YearMonth] = _PREVIOUS_YEARMONTH
        )
    )&lt;/LI-CODE&gt;
&lt;P&gt;Result in my sample is as below.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Jul 2022 09:23:23 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-07-05T09:23:23Z</dc:date>
    <item>
      <title>To calculate previous month of sales</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2608394#M75568</link>
      <description>&lt;P&gt;I am using below formula to calculate previous month but i get black values for few months and other months are blank values as shpwn below, not sure whats the issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;PM Book RR = &lt;/SPAN&gt;&lt;SPAN&gt;Calculate&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;SUM&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Sales vs Inv'[Book RR]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;SPAN&gt;FILTER&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;ALL&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'_DimDate (2)'[MonthOfYear]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;SPAN&gt;'_DimDate (2)'[MonthOfYear]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'_DimDate (2)'[MonthOfYear]&lt;/SPAN&gt;&lt;SPAN&gt;)-&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;img /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly suggest.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 29 Jun 2022 06:02:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2608394#M75568</guid>
      <dc:creator>pmadam</dc:creator>
      <dc:date>2022-06-29T06:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: To calculate previous month of sales</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2608576#M75583</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="76400" data-lia-user-login="pmadam" class="lia-mention lia-mention-user"&gt;pmadam&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Please try&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;PM Book RR =
CALCULATE (
    SUM ( 'Sales vs Inv'[Book RR] ),
    REMOVEFILTERS ( '_DimDate (2)' ),
    '_DimDate (2)'[MonthOfYear]
        = MAX ( '_DimDate (2)'[MonthOfYear] ) - 1
)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 29 Jun 2022 07:30:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2608576#M75583</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-06-29T07:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: To calculate previous month of sales</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2608653#M75586</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not every month has a Book RR. So for month 11 there is a value to retrieve for month 11-1 = 10, but for 10 there is nothing for month number 10-1 = 9, and so on. The "-1" you add in your filter decreases the month number by exactly 1, not down to the one with one rank lower.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe it makes sense to have previous month as 0/blank if there is data for October (10) but nothing for September (9)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But maybe you want to see the sales for the most recent month where there has been a sale. I'm not sure how your data is structured, you'd have to share some for me to be more specific. I suppose you could create a summarized table with the numbers you show here, create a calculated column with the rank for each month number, and then use this rank in your filter to get the most recent month for each. Another way could be to nest if statements: if sales for month-1 is blank, pick sales for month-2, and so on.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But there might be an easier solution somehow.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 08:03:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2608653#M75586</guid>
      <dc:creator>TomasAndersson</dc:creator>
      <dc:date>2022-06-29T08:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: To calculate previous month of sales</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2608696#M75589</link>
      <description>&lt;P&gt;EDIT: See tamerj1s post for a smarter solution.&lt;BR /&gt;&lt;BR /&gt;See below for example with nested ifs. It's not pretty, but it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PM Book RR = 

VAR __monthsToDecrease = if(
    CALCULATE (
    SUM ( 'Sales vs Inv'[Book RR] ),
        FILTER(
            ALL(''_DimDate (2)'[MonthOfYear]),'_DimDate (2)'[MonthOfYear] = MAX('_DimDate (2)'[MonthOfYear])-1)
    )    &amp;gt; 0,1,2) //nest additional times to include possibility that __monthsToDecrease might have to be 3, 4 etc...

return

CALCULATE (
    SUM ( 'Sales vs Inv'[Book RR] ),
        FILTER(
            ALL('_DimDate (2)'[MonthOfYear]),'_DimDate (2)'[MonthOfYear] = MAX('_DimDate (2)'[MonthOfYear])-__monthsToDecrease)
)      ​&lt;/LI-CODE&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;</description>
      <pubDate>Wed, 29 Jun 2022 08:23:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2608696#M75589</guid>
      <dc:creator>TomasAndersson</dc:creator>
      <dc:date>2022-06-29T08:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: To calculate previous month of sales</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2608697#M75590</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="404599" data-lia-user-login="TomasAndersson" class="lia-mention lia-mention-user"&gt;TomasAndersson&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Please use&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;PM Book RR =
VAR CurrentMonthOfYear =
    MAX ( '_DimDate (2)'[MonthOfYear] )
VAR PreviousMonth =
    MAXX (
        FILTER (
            ALL ( '_DimDate (2)'[MonthOfYear] ),
            '_DimDate (2)'[MonthOfYear] &amp;lt; CurrentMonthOfYear
        ),
        '_DimDate (2)'[MonthOfYear]
    )
RETURN
    CALCULATE (
        SUM ( 'Sales vs Inv'[Book RR] ),
        REMOVEFILTERS ( '_DimDate (2)' ),
        '_DimDate (2)'[MonthOfYear] = PreviousMonth
    )&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 29 Jun 2022 08:19:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2608697#M75590</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-06-29T08:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: To calculate previous month of sales</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2608716#M75591</link>
      <description>&lt;P&gt;Ah, a lot more sofisticated! Great suggestion&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 08:23:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2608716#M75591</guid>
      <dc:creator>TomasAndersson</dc:creator>
      <dc:date>2022-06-29T08:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: To calculate previous month of sales</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2610366#M75684</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="404599" data-lia-user-login="TomasAndersson" class="lia-mention lia-mention-user"&gt;TomasAndersson&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;I got it working for multiple solutions but its now showing previous month for January of each year.&lt;/P&gt;&lt;P&gt;Please suggest where I wrong&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;PM Book RR = &lt;/SPAN&gt;&lt;SPAN&gt;Calculate&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;SUM&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Sales vs Inv'[Book RR]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;SPAN&gt;FILTER&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;ALL&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Sales vs Inv'[Time.Month]&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;SPAN&gt;'Sales vs Inv'[Time.Month]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Sales vs Inv'[Time.Month]&lt;/SPAN&gt;&lt;SPAN&gt;)-&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;PM Book RR1 = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;SUM&lt;/SPAN&gt;&lt;SPAN&gt; ( &lt;/SPAN&gt;&lt;SPAN&gt;'Sales vs Inv'[Book RR]&lt;/SPAN&gt;&lt;SPAN&gt; ),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;removeFILTERS&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;'Sales vs Inv'[Time.Month]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;'Sales vs Inv'[Time.Month]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;= &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt; ( &lt;/SPAN&gt;&lt;SPAN&gt;'Sales vs Inv'[Time.Month]&lt;/SPAN&gt;&lt;SPAN&gt; ) - &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 19:38:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2610366#M75684</guid>
      <dc:creator>pmadam</dc:creator>
      <dc:date>2022-06-29T19:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: To calculate previous month of sales</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2610482#M75691</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="76400" data-lia-user-login="pmadam" class="lia-mention lia-mention-user"&gt;pmadam&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you have to have a year month sequential number column. If you already have year month number in the format YYYYMM then you can RANKX - ASC - DENSE based on this column. Then use this column in the measure&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 21:18:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2610482#M75691</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-06-29T21:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: To calculate previous month of sales</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2619386#M76232</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="76400" data-lia-user-login="pmadam" class="lia-mention lia-mention-user"&gt;pmadam&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your statement, I suggest you to combine [Year] and [&lt;SPAN&gt;Time.Month&lt;/SPAN&gt;] into one column as a key column in your calculation. Using two columns&amp;nbsp;[Year] and [&lt;SPAN&gt;Time.Month&lt;/SPAN&gt;] will make your calculation complex. Thiis new column should be in number type. Note:&amp;nbsp;&amp;nbsp;[Year] and [&lt;SPAN&gt;Time.Month&lt;/SPAN&gt;] should be in number type as well.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;YearMonth = [Year]*100 + [Time.Month]&lt;/LI-CODE&gt;
&lt;P&gt;Measure:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;PM Book RR1 =
VAR _PREVIOUS_YEARMONTH =
    MAXX (
        FILTER (
            ALL ( 'Sales vs Inv' ),
            'Sales vs Inv'[YearMonth] &amp;lt; MAX ( 'Sales vs Inv'[YearMonth] )
        ),
        'Sales vs Inv'[YearMonth]
    )
RETURN
    CALCULATE (
        SUM ( 'Sales vs Inv'[Book RR] ),
        FILTER (
            ALL ( 'Sales vs Inv' ),
            'Sales vs Inv'[YearMonth] = _PREVIOUS_YEARMONTH
        )
    )&lt;/LI-CODE&gt;
&lt;P&gt;Result in my sample is as below.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 09:23:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/To-calculate-previous-month-of-sales/m-p/2619386#M76232</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-07-05T09:23:23Z</dc:date>
    </item>
  </channel>
</rss>

