<?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: How get last previous date from variable date in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3497360#M134003</link>
    <description>&lt;P&gt;Just curious, did you try using EOMONTH and -1.&lt;/P&gt;
&lt;P&gt;I cannot read spanish else would have refined your DAX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;measure1 =
VAR _PrevMonthEndDate = EOMONTH ( LastDate, -1 )
VAR _resultLastTxDate =
    MAXX (
        FILTER ( ALL ( 'Table1'[Date] ), 'Table1'[Date] &amp;lt;= _PrevMonthEndDate),
        'Table1'[Date]
    )
RETURN    _resultLastTxDate&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Oct 2023 20:53:52 GMT</pubDate>
    <dc:creator>sevenhills</dc:creator>
    <dc:date>2023-10-25T20:53:52Z</dc:date>
    <item>
      <title>How get last previous date from variable date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3497262#M133997</link>
      <description>&lt;P&gt;Hi, I have a Fact table linked to DimDate.&lt;/P&gt;&lt;P&gt;I Need get last date previous month from date passed as measure.&lt;/P&gt;&lt;P&gt;eg.&lt;/P&gt;&lt;P&gt;Measure:&lt;/P&gt;&lt;P&gt;LastDate =&amp;nbsp;2023-10-25&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dax&lt;/P&gt;&lt;P&gt;Var lastDate = LastDate&lt;/P&gt;&lt;P&gt;Var vYear = Year(LastDate)&lt;/P&gt;&lt;P&gt;Var vMonth = Month(LastDate)&lt;/P&gt;&lt;P&gt;Var firstdate = Date(vYear, vMonth, 1)&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;The last day of previous month of my fact table is 2023-09-29&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need a DAX to return&amp;nbsp;2023-09-29&amp;nbsp; instead of 2023-09-30(last day of previous month of DimDate table)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 19:20:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3497262#M133997</guid>
      <dc:creator>RafaelRSantosBR</dc:creator>
      <dc:date>2023-10-25T19:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: How get last previous date from variable date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3497296#M133999</link>
      <description>&lt;P&gt;I make this DAX, but i think have most elegant way to do.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I will wait for responses, thanks&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 19:43:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3497296#M133999</guid>
      <dc:creator>RafaelRSantosBR</dc:creator>
      <dc:date>2023-10-25T19:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: How get last previous date from variable date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3497360#M134003</link>
      <description>&lt;P&gt;Just curious, did you try using EOMONTH and -1.&lt;/P&gt;
&lt;P&gt;I cannot read spanish else would have refined your DAX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;measure1 =
VAR _PrevMonthEndDate = EOMONTH ( LastDate, -1 )
VAR _resultLastTxDate =
    MAXX (
        FILTER ( ALL ( 'Table1'[Date] ), 'Table1'[Date] &amp;lt;= _PrevMonthEndDate),
        'Table1'[Date]
    )
RETURN    _resultLastTxDate&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 20:53:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3497360#M134003</guid>
      <dc:creator>sevenhills</dc:creator>
      <dc:date>2023-10-25T20:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: How get last previous date from variable date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3497437#M134008</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="636768" data-lia-user-login="RafaelRSantosBR" class="lia-mention lia-mention-user"&gt;RafaelRSantosBR&lt;/a&gt;, here is my suggested solution.&lt;/P&gt;&lt;P&gt;Create a measure with this DAX expression. I think you need to query the FactTable, but remove the filters from both the FactTable and the dimDate table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last Date in Previous Month from Fact Table = 
    VAR vLastDate = [LastDate]
    VAR vPrevMonth = EDATE(vLastDate, -1)
    VAR vYear = YEAR(vPrevMonth)
    VAR vMonth = MONTH(vPrevMonth)

    RETURN 
        CALCULATE(
            MAX(FactTable[Date]),
            ALL(FactTable),
            ALL(dimDate),
            YEAR(FactTable[Date]) = vYear,
            MONTH(FactTable[Date]) = vMonth
        )&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, 25 Oct 2023 22:10:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3497437#M134008</guid>
      <dc:creator>EylesIT</dc:creator>
      <dc:date>2023-10-25T22:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: How get last previous date from variable date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3499390#M134161</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="635900" data-lia-user-login="EylesIT" class="lia-mention lia-mention-user"&gt;EylesIT&lt;/a&gt;&amp;nbsp;your calculation return the last day of previous month, but not the last day of previous day that exists in fact table.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I made some updates in your DAX, because the fact table doesn't have date value, just the foreign key of date value. Follows the code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last Date in Previous Month from Fact Table = 
    VAR vLastDate = [UltimaData]
    VAR vPrevMonth = EDATE(vLastDate, -1)
    VAR vYear = YEAR(vPrevMonth)
    VAR vMonth = MONTH(vPrevMonth)

    RETURN 
        CALCULATE(
            MAX('Publico DimData'[Data]),
            ALL('Investimento FatoEvolucaoFundo'),
            ALL('Publico DimData'),
            YEAR('Publico DimData'[Data]) = vYear,
            MONTH('Publico DimData'[Data]) = vMonth
        )&lt;/LI-CODE&gt;&lt;P&gt;Follows the model.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 15:33:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3499390#M134161</guid>
      <dc:creator>RafaelRSantosBR</dc:creator>
      <dc:date>2023-10-26T15:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: How get last previous date from variable date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3499410#M134164</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="29249" data-lia-user-login="sevenhills" class="lia-mention lia-mention-user"&gt;sevenhills&lt;/a&gt;&amp;nbsp;, thanks for reply.&lt;/P&gt;&lt;P&gt;Your DAX return the last day of previous month of Dimension Date Table, and not the last day of previous month of Fact Table.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I made this updates to work:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;measure1 = 
VAR _PrevMonthEndDate = EOMONTH ( [UltimaData], -1 )
VAR _resultLastTxDate =
    MAXX (
        FILTER ( ALL ( 'Publico DimData'[Data] ), 'Publico DimData'[Data] &amp;lt;= _PrevMonthEndDate),
        'Publico DimData'[Data]
    )
RETURN
_resultLastTxDate&lt;/LI-CODE&gt;&lt;P&gt;Thanks for help&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 15:42:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3499410#M134164</guid>
      <dc:creator>RafaelRSantosBR</dc:creator>
      <dc:date>2023-10-26T15:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: How get last previous date from variable date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3500082#M134193</link>
      <description>&lt;P&gt;I was not sure whether it worked or not...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, I see what you want is previous month max transaction date based on certain colum. I will recommend to try this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is the DAX from Adventure Works DW 2020&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Prev.Month - Max.Sales.Tx.Date - Sales Amount = 
var _PrevMonthStartDate  = EOMONTH ( [Last Sales Tx Date], -2 ) + 1 
var _PrevMonthEndDate    = EOMONTH ( [Last Sales Tx Date], -1 )
var _LastDateInPreviousMonthTx =  LASTNONBLANK ( 
       Filter( all('Date'[Date]), 
            'Date'[Date] &amp;gt;= _PrevMonthStartDate 
            &amp;amp;&amp;amp; 'Date'[Date] &amp;lt;= _PrevMonthEndDate)
       , CALCULATE ( SUM ( Sales[Sales Amount] ) )) 
return _LastDateInPreviousMonthTx&lt;/LI-CODE&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;Similarly,&amp;nbsp;You can do like this by adjusting the fact table column and dim date column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;measure1 = 
var _PrevMonthStartDate  = EOMONTH ( [UltimaData], -2 ) + 1 
var _PrevMonthEndDate    = EOMONTH ( [UltimaData], -1 )
var _LastDateInPreviousMonthTx =  LASTNONBLANK ( 
        Filter( all('Dim Date'[Date]),
             'Dim Date'[Date] &amp;gt;= _PrevMonthStartDate 
             &amp;amp;&amp;amp; 'Dim Date'[Date] &amp;lt;= _PrevMonthEndDate)
        , CALCULATE ( SUM ( FactTable[Sales Amount] ) )) 
return _LastDateInPreviousMonthTx&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 22:38:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-get-last-previous-date-from-variable-date/m-p/3500082#M134193</guid>
      <dc:creator>sevenhills</dc:creator>
      <dc:date>2023-10-26T22:38:03Z</dc:date>
    </item>
  </channel>
</rss>

