<?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: Same period previous N months in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/3685462#M143152</link>
    <description>&lt;P&gt;Is there any hardcode version in which you can see the sales amount of same period last month.&lt;BR /&gt;&lt;BR /&gt;for example, if i have data of 1 dec to 14 dec then it should display data of 1 nov to 14 nov.&lt;/P&gt;</description>
    <pubDate>Wed, 07 Feb 2024 10:31:21 GMT</pubDate>
    <dc:creator>ankur1991</dc:creator>
    <dc:date>2024-02-07T10:31:21Z</dc:date>
    <item>
      <title>Same period previous N months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121310#M48600</link>
      <description>&lt;P&gt;I want to calculate total sales for previous N months for the same period according to the slicer. Eg if in slicer I select range from 1-10-21 to 3-10-21 the my column chart should display total sales for previous N months within this range.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote following Dax measure for the same but not getting desired result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;same period = CALCULATE(SUM(financials[ Sales]),DATESINPERIOD('Date'[Date],MAX('Date'[Date]), -'Select N'[N Value],MONTH),FILTER(financials,AND(financials[Date]&amp;gt;=MIN('Date'[Date]),financials[Date]&amp;lt;=MAX('Date'[Date]))))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Any suggestions are apprecited.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 07 Oct 2021 10:39:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121310#M48600</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-07T10:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Same period previous N months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121414#M48604</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use the DATEADD function to move the period back a set number of months&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;same period = 
VAR _SelectedN = SELECTEDVALUE('Select N'[N Value])
VAR _Result = 
CALCULATE(
    SUM(financials[Sales]),
    DATEADD('Date'[Date], -_SelectedN, MONTH)
)
RETURN
    _Result&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 07 Oct 2021 11:44:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121414#M48604</guid>
      <dc:creator>PaulOlding</dc:creator>
      <dc:date>2021-10-07T11:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Same period previous N months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121446#M48607</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="150936" data-lia-user-login="PaulOlding" class="lia-mention lia-mention-user"&gt;PaulOlding&lt;/a&gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;if in slicer I select range from 1-10-21 to 3-10-21 the my column chart should display total sales for previous N months within &lt;STRONG&gt;this&lt;/STRONG&gt; range.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have already achieved result for total sales for previour N months&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:02:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121446#M48607</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-07T12:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: Same period previous N months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121467#M48609</link>
      <description>&lt;P&gt;Sorry, I don't understand.&lt;/P&gt;&lt;P&gt;If the user selects&amp;nbsp;&lt;SPAN&gt;1-10-21 to 3-10-21 and previous 3 months, what dates should we be looking at?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;*Also, is&amp;nbsp;1-10-21 in d-m-yy or m-d-yy?&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:11:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121467#M48609</guid>
      <dc:creator>PaulOlding</dc:creator>
      <dc:date>2021-10-07T12:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: Same period previous N months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121491#M48610</link>
      <description>&lt;P&gt;If date range for a particular month is selected than for every selected N previous months, total sales pertaining to only that date range should be displayed. The format is d-m-yy.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:18:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121491#M48610</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-07T12:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Same period previous N months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121518#M48615</link>
      <description>&lt;P&gt;Does that mean these dates?&lt;/P&gt;&lt;P&gt;1-9-2021&lt;/P&gt;&lt;P&gt;2-9-2021&lt;/P&gt;&lt;P&gt;3-9-2021&lt;/P&gt;&lt;P&gt;1-8-2021&lt;/P&gt;&lt;P&gt;2-8-2021&lt;/P&gt;&lt;P&gt;3-8-2021&lt;/P&gt;&lt;P&gt;1-7-2021&lt;/P&gt;&lt;P&gt;2-7-2021&lt;/P&gt;&lt;P&gt;3-7-2021&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:35:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121518#M48615</guid>
      <dc:creator>PaulOlding</dc:creator>
      <dc:date>2021-10-07T12:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Same period previous N months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121584#M48623</link>
      <description>&lt;P&gt;yes&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 13:09:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121584#M48623</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-07T13:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Same period previous N months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121617#M48626</link>
      <description>&lt;P&gt;OK.&amp;nbsp; How many previous months can the user select?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering if it's better to have a pattern like:&lt;/P&gt;&lt;P&gt;IF(N Value &amp;gt;= 1, CALCULATE(..., DATEADD(Date, -1, MONTH)&amp;nbsp;&lt;/P&gt;&lt;P&gt;+&amp;nbsp;IF(N Value &amp;gt;= 2, CALCULATE(..., DATEADD(Date, -2, MONTH)&amp;nbsp;&lt;/P&gt;&lt;P&gt;+ IF(N Value &amp;gt;= 3, CALCULATE(..., DATEADD(Date, -3, MONTH)&amp;nbsp;&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... or if it's better to construct a variable with the required dates manually.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The advantage of DATEADD is it handles the complexity of months having different numbers of days.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, what happens if the user selects 24-2-2021 to 3-3-2021?&amp;nbsp; February only has 28 days but moved back one month you should probably include 29, 20 &amp;amp; 31 January.&lt;/P&gt;&lt;P&gt;What if they select&amp;nbsp;24-2-2021 to 28-2-2021?&amp;nbsp; Does that mean we should go from 24 Jan to 31 Jan?&amp;nbsp; or 24 Jan to 28 Jan?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 13:17:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2121617#M48626</guid>
      <dc:creator>PaulOlding</dc:creator>
      <dc:date>2021-10-07T13:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Same period previous N months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2123861#M48702</link>
      <description>&lt;P&gt;I wrote something like this.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;same period = CALCULATE(SUM(financials[ Sales]),DATESINPERIOD('Date'[Date],MAX('Date'[Date]), -'Select N'[N Value],MONTH),DATESBETWEEN('Date'[Date],MIN('Date'[Date]),MAX('Date'[Date])))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Is it correct?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 08 Oct 2021 10:20:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2123861#M48702</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-08T10:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: Same period previous N months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2125240#M48737</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No, i don't think so.&lt;/P&gt;&lt;P&gt;For a start you'll get a syntax error from this&amp;nbsp;&lt;SPAN&gt;'Select N'[N Value].&amp;nbsp; I suspect you'd want it to be SELECTEDVALUE('Select N'[N Value]).&amp;nbsp; However, even then you won;t get the right answer.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;We can break the measure formula down to see why:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;same period = 
CALCULATE(
    SUM(financials[Sales]),
    DATESINPERIOD('Date'[Date],MAX('Date'[Date]), -SELECTEDVALUE('Select N'[N Value]),MONTH),
    DATESBETWEEN('Date'[Date],MIN('Date'[Date]),MAX('Date'[Date]))
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;We're using CALCULATe so we're going to alter the filter context.&amp;nbsp; The arguments we pass for the second parameter onwards are tables.&amp;nbsp; Let's see what they'll contain for the example selection: Date = 1-Oct-2021 to 3-Oct-2021&lt;/P&gt;&lt;P&gt;N Value = 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATESINPERIOD&lt;/P&gt;&lt;P&gt;&lt;A href="https://dax.guide/datesinperiod/" target="_blank"&gt;https://dax.guide/datesinperiod/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;This will return all the dates going back 3 months from the start date of 3-Oct-2021.&amp;nbsp; So all dates between 4-Jul-2021 and 3-Oct-2021&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATESBETWEEN&lt;/P&gt;&lt;P&gt;&lt;A href="https://dax.guide/datesbetween/" target="_blank"&gt;https://dax.guide/datesbetween/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;This will return all the dates between 1-Oct-2021 and 3-Oct-2021.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, the net effect of those 2 filters in the calculate function is the dates that are in both results.&amp;nbsp; That's&amp;nbsp;1-Oct-2021 to 3-Oct-2021.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a version of your measure that allows you to go back 4 periods.&amp;nbsp; If you need more you can add more IF statements in the same format&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;same period 2 = 
VAR _SelectedN = SELECTEDVALUE('Select N'[N Value])
VAR _Result = 
IF(_SelectedN &amp;gt;= 1, CALCULATE( SUM(financials[Sales]), DATEADD('Date'[Date], -1, MONTH) ))
    + IF(_SelectedN &amp;gt;= 2, CALCULATE( SUM(financials[Sales]), DATEADD('Date'[Date], -2, MONTH) ))
    + IF(_SelectedN &amp;gt;= 3, CALCULATE( SUM(financials[Sales]), DATEADD('Date'[Date], -3, MONTH) ))
    + IF(_SelectedN &amp;gt;= 4, CALCULATE( SUM(financials[Sales]), DATEADD('Date'[Date], -4, MONTH) ))
RETURN 
    _Result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 17:46:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2125240#M48737</guid>
      <dc:creator>PaulOlding</dc:creator>
      <dc:date>2021-10-09T17:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: Same period previous N months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2162555#M50002</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also create a measure like so:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;same period = 
VAR SelectedDates_ =
    VALUES ( 'Date'[Date] )
VAR SelectedDays_ =
    VALUES ( 'Date'[Day] )
RETURN
    CALCULATE (
        SUM ( financials[Sales] ),
        DATESINPERIOD (
            'Date'[Date],
            MAX ( 'Date'[Date] ),
            - 'Select N'[Select N Value] - 1,
            MONTH
        ),
        'Date'[Day] IN SelectedDays_,
        NOT ( 'Date'[Date] IN SelectedDates_ )
    )
&lt;/LI-CODE&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;Best Regards,&lt;/P&gt;
&lt;P&gt;Icey&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If this post&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;helps&lt;/STRONG&gt;&lt;SPAN&gt;, then please consider&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 07:01:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/2162555#M50002</guid>
      <dc:creator>Icey</dc:creator>
      <dc:date>2021-10-29T07:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: Same period previous N months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/3685462#M143152</link>
      <description>&lt;P&gt;Is there any hardcode version in which you can see the sales amount of same period last month.&lt;BR /&gt;&lt;BR /&gt;for example, if i have data of 1 dec to 14 dec then it should display data of 1 nov to 14 nov.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 10:31:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Same-period-previous-N-months/m-p/3685462#M143152</guid>
      <dc:creator>ankur1991</dc:creator>
      <dc:date>2024-02-07T10:31:21Z</dc:date>
    </item>
  </channel>
</rss>

