<?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 Max date by group, rewrite measure to create calculated column in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Max-date-by-group-rewrite-measure-to-create-calculated-column/m-p/3402914#M128523</link>
    <description>&lt;P&gt;I have the following calculated table from this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Tbl = 
SUMMARIZECOLUMNS( 
	dAssets[Ticker], 
	dDates[Date], 
	"Purchases", [Shares purchased], 
	"Sales", [Shares sold] 
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I created the following &lt;U&gt;&lt;STRONG&gt;measure&lt;/STRONG&gt;&lt;/U&gt; that retrieves the last purchase date prior to each sale row...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last purchase date before respective sale = 
VAR Ticker_Ref = MAX( Tbl[Ticker] )
VAR Date_Ref = MAX( Tbl[Date] )
RETURN
	MAXX( 
		FILTER( 
			ALLSELECTED( Tbl ), 
			[Ticker] = Ticker_Ref &amp;amp;&amp;amp; 
			[Date] &amp;lt;= Date_Ref &amp;amp;&amp;amp; 
			[Purchases] &amp;lt;&amp;gt; BLANK() 
		), 
		[Date] 
	)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... which works just fine when dropped to a table visual:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800000"&gt;&lt;STRONG&gt;I tried to produce those same results above as a &lt;U&gt;calculated column&lt;/U&gt; but I keep getting wrong results. How can I get that to work?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I'm a DAX newbie, I still have a hard time reproducing a measure code as a calculated column or vice-versa...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The closest I got was this...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last purchase date before respective sale = 
VAR Date_Ref = MAX( Tbl[Date] )
RETURN
	CALCULATE( 
		MAX( Tbl[Date] ), 
		ALLEXCEPT( Tbl, Tbl[Ticker] ), 
		Tbl[Date] &amp;lt;= Date_Ref, 
		Tbl[Purchases] &amp;lt;&amp;gt; BLANK() 
	)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... but it returns wrong results (max purchase row date per group of tickers, instead of max purchase row date within each group of tickers prior to or up to each respective sale row date):&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And before one suggests I should think long and hard before resorting to calculated columns as opposed to measures: I've already done such philosophical conundrum and realized that for this particular application, which is producing that piece of calculation, and others that follow, in order to reach a particular (and very complex) calculation goal, I have no other choice but go with&amp;nbsp;calculated columns.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Aug 2023 20:12:59 GMT</pubDate>
    <dc:creator>leolapa_br</dc:creator>
    <dc:date>2023-08-28T20:12:59Z</dc:date>
    <item>
      <title>Max date by group, rewrite measure to create calculated column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Max-date-by-group-rewrite-measure-to-create-calculated-column/m-p/3402914#M128523</link>
      <description>&lt;P&gt;I have the following calculated table from this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Tbl = 
SUMMARIZECOLUMNS( 
	dAssets[Ticker], 
	dDates[Date], 
	"Purchases", [Shares purchased], 
	"Sales", [Shares sold] 
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I created the following &lt;U&gt;&lt;STRONG&gt;measure&lt;/STRONG&gt;&lt;/U&gt; that retrieves the last purchase date prior to each sale row...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last purchase date before respective sale = 
VAR Ticker_Ref = MAX( Tbl[Ticker] )
VAR Date_Ref = MAX( Tbl[Date] )
RETURN
	MAXX( 
		FILTER( 
			ALLSELECTED( Tbl ), 
			[Ticker] = Ticker_Ref &amp;amp;&amp;amp; 
			[Date] &amp;lt;= Date_Ref &amp;amp;&amp;amp; 
			[Purchases] &amp;lt;&amp;gt; BLANK() 
		), 
		[Date] 
	)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... which works just fine when dropped to a table visual:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800000"&gt;&lt;STRONG&gt;I tried to produce those same results above as a &lt;U&gt;calculated column&lt;/U&gt; but I keep getting wrong results. How can I get that to work?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I'm a DAX newbie, I still have a hard time reproducing a measure code as a calculated column or vice-versa...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The closest I got was this...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last purchase date before respective sale = 
VAR Date_Ref = MAX( Tbl[Date] )
RETURN
	CALCULATE( 
		MAX( Tbl[Date] ), 
		ALLEXCEPT( Tbl, Tbl[Ticker] ), 
		Tbl[Date] &amp;lt;= Date_Ref, 
		Tbl[Purchases] &amp;lt;&amp;gt; BLANK() 
	)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... but it returns wrong results (max purchase row date per group of tickers, instead of max purchase row date within each group of tickers prior to or up to each respective sale row date):&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And before one suggests I should think long and hard before resorting to calculated columns as opposed to measures: I've already done such philosophical conundrum and realized that for this particular application, which is producing that piece of calculation, and others that follow, in order to reach a particular (and very complex) calculation goal, I have no other choice but go with&amp;nbsp;calculated columns.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2023 20:12:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Max-date-by-group-rewrite-measure-to-create-calculated-column/m-p/3402914#M128523</guid>
      <dc:creator>leolapa_br</dc:creator>
      <dc:date>2023-08-28T20:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Max date by group, rewrite measure to create calculated column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Max-date-by-group-rewrite-measure-to-create-calculated-column/m-p/3402952#M128529</link>
      <description>&lt;P&gt;Managed to get to the bottom of this thing...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last purchase date before respective sale = 
VAR Ticker_Ref = Tbl[Ticker]
VAR Date_Ref = Tbl[Date]
RETURN
	MAXX( 
		FILTER( 
			ALL( Tbl ), 
			Tbl[Ticker] = Ticker_Ref &amp;amp;&amp;amp; 
			Tbl[Date] &amp;lt;= Date_Ref &amp;amp;&amp;amp; 
			Tbl[Purchases] &amp;lt;&amp;gt; BLANK() 
		), 
		Tbl[Date] 
	)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 28 Aug 2023 20:25:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Max-date-by-group-rewrite-measure-to-create-calculated-column/m-p/3402952#M128529</guid>
      <dc:creator>leolapa_br</dc:creator>
      <dc:date>2023-08-28T20:25:55Z</dc:date>
    </item>
  </channel>
</rss>

