<?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 Calculate Previous Month Sales up to a specific date in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Previous-Month-Sales-up-to-a-specific-date/m-p/3199137#M116220</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I have the following functions:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Sales MTD = 
CALCULATE(
    [Total Sales],
    DATESMTD(
        Calendar_Lookup[Date]
    )
)&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;&lt;LI-CODE lang="markup"&gt;Sales MTD Previous = 
CALCULATE(
    [Sales MTD],
    DATEADD(
        Calendar_Lookup[Date],
        -1,
        MONTH
        )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to calculate the Sales MTD Previous but up to a specific date (max date).&lt;BR /&gt;&lt;BR /&gt;My model looks like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Any help is appreciated.&lt;/P&gt;</description>
    <pubDate>Fri, 21 Apr 2023 01:44:41 GMT</pubDate>
    <dc:creator>aleivar</dc:creator>
    <dc:date>2023-04-21T01:44:41Z</dc:date>
    <item>
      <title>Calculate Previous Month Sales up to a specific date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Previous-Month-Sales-up-to-a-specific-date/m-p/3199137#M116220</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I have the following functions:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Sales MTD = 
CALCULATE(
    [Total Sales],
    DATESMTD(
        Calendar_Lookup[Date]
    )
)&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;&lt;LI-CODE lang="markup"&gt;Sales MTD Previous = 
CALCULATE(
    [Sales MTD],
    DATEADD(
        Calendar_Lookup[Date],
        -1,
        MONTH
        )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to calculate the Sales MTD Previous but up to a specific date (max date).&lt;BR /&gt;&lt;BR /&gt;My model looks like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Any help is appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 01:44:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Previous-Month-Sales-up-to-a-specific-date/m-p/3199137#M116220</guid>
      <dc:creator>aleivar</dc:creator>
      <dc:date>2023-04-21T01:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Previous Month Sales up to a specific date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Previous-Month-Sales-up-to-a-specific-date/m-p/3199296#M116228</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I tried to create a sample pbix file like below.&lt;/P&gt;
&lt;P&gt;Please check the below picture and the attached pbix file.&lt;/P&gt;
&lt;P&gt;I hope the below can provide some ideas on how to create a solution for your datamodel.&lt;/P&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;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sales MTD prevmonth upto specific date: =
VAR _selectedyear =
    YEAR ( MAX ( 'Calendar'[Date] ) )
VAR _selectedmonth =
    MONTH ( MAX ( 'Calendar'[Date] ) )
VAR _prevmonthdate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), DATEADD ( 'Calendar'[Date], -1, MONTH ) )
RETURN
    IF (
        NOT ISBLANK ( _prevmonthdate ),
        IF (
            _selectedmonth &amp;lt;&amp;gt; 1,
            CALCULATE (
                [Total sales:],
                FILTER (
                    ALL ( 'Calendar' ),
                    YEAR ( [Date] ) = _selectedyear
                        &amp;amp;&amp;amp; MONTH ( [Date] ) = _selectedmonth - 1
                        &amp;amp;&amp;amp; 'Calendar'[Date] &amp;lt;= _prevmonthdate
                )
            ),
            CALCULATE (
                [Total sales:],
                FILTER (
                    ALL ( 'Calendar' ),
                    YEAR ( [Date] ) = _selectedyear - 1
                        &amp;amp;&amp;amp; MONTH ( [Date] ) = 12
                        &amp;amp;&amp;amp; 'Calendar'[Date] &amp;lt;= _prevmonthdate
                )
            )
        )
    )
&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>Fri, 21 Apr 2023 03:32:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Previous-Month-Sales-up-to-a-specific-date/m-p/3199296#M116228</guid>
      <dc:creator>Jihwan_Kim</dc:creator>
      <dc:date>2023-04-21T03:32:54Z</dc:date>
    </item>
  </channel>
</rss>

