<?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: MAX Prior Period based on LastDate return value in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734325#M1919</link>
    <description>&lt;P&gt;Please let me know if this link does not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://onedrive.live.com/?authkey=%21ANQYX5UCHJaHyuU&amp;amp;id=E1D90AB70FBCB9DF%21805&amp;amp;cid=E1D90AB70FBCB9DF" target="_blank"&gt;https://onedrive.live.com/?authkey=%21ANQYX5UCHJaHyuU&amp;amp;id=E1D90AB70FBCB9DF%21805&amp;amp;cid=E1D90AB70FBCB9DF&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You'll be able to see several examples of how it does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Respectfully,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Robert&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jul 2019 15:15:34 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-07-08T15:15:34Z</dc:date>
    <item>
      <title>MAX Prior Period based on LastDate return value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/731174#M1769</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two measures which return the price based on the max date and both are working correctly.&amp;nbsp; What I am looking to do is similar to DateAdd but I don't believe DateAdd can be combined with MAX/MAXX.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried to filter using as I have a date dimension but it's returning a list of values instead of a scalar value :&lt;STRONG&gt;FILTER(ALL('date table'[Date ]);'date table'[Date ]&amp;lt;=DATE(YEAR(MAX('date table'[Date ]))-1;MONTH(MAX('date table'[Date ]));DAY(MAX('date table'[Date ]))))&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Measure 2 = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;MAXX (&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;TOPN (&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;1,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FILTER ( 'Benchmarks_PowerBI', 'Benchmarks_PowerBI'[ Price ] &amp;lt;&amp;gt; BLANK ()),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Benchmarks_PowerBI[Date], DESC&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Benchmarks_PowerBI[ Price ]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;)&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;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Measure 5 = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var _max = CALCULATE(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;MAX(DimDate[Date]),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;'Benchmarks_PowerBI','Benchmarks_PowerBI'[ Price ]&amp;lt;&amp;gt; BLANK(),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ALL ( Benchmarks_PowerBI ))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;SUMX(FILTER(Benchmarks_PowerBI, Benchmarks_PowerBI[Date]=_max),Benchmarks_PowerBI[ Price ])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Ultimately, I'm looking for something like this:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;Measure 2 = 
**Current Period**VAR __max = MAX('Table5'[Fiscal Year])
**Prior Period**VAR __min = MIN('Table5'[Fiscal Year])
RETURN
SUMX(FILTER('Table5',[Fiscal Year]=__min),[Rate]) - SUMX(FILTER('Table5',[Fiscal Year]=__max),[Rate])&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Respectfully,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Robert&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 03 Jul 2019 18:12:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/731174#M1769</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-03T18:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: MAX Prior Period based on LastDate return value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/732116#M1814</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone could understand what you really need, then maybe someone would be able to help you...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Darek&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 23:21:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/732116#M1814</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-04T23:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: MAX Prior Period based on LastDate return value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734147#M1905</link>
      <description>&lt;P&gt;Hi Darek,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a fact table, benchmarks, a dimbenchmark, and a dimdate table in the model.&amp;nbsp; Essentially, we are looking to create 1,3, 5 year comparisons based on the current context i.e. year is 2019.&amp;nbsp; For 2019, we would want to return the most recent date with a price for a ticker.&amp;nbsp; Then, we would want to shift the context to grab the most recent price from the previous year.&amp;nbsp; For example, we would be comparing the closing price of "A" on 12-31-2018 to the closing price of the most recent day with a price.&amp;nbsp; Essentially, we are looking to a YTD comparision.&amp;nbsp; We would be looking to create the same mesure for QTD and 1-3-5 year from the date of the current price.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Respectfully,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Robert&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 13:28:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734147#M1905</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-08T13:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: MAX Prior Period based on LastDate return value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734188#M1908</link>
      <description>&lt;P&gt;OK. Would you please obtain a shareable link to an example file and post it? I wanna see your model and data. You can get a link to a file if you put the file on OneDrive, GoogleDrive, Dropbox... or some other cloud storage service. if you do that, please do not forget to make the link accessible to anyone (you have to set permissions right).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Darek&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 13:53:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734188#M1908</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-08T13:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: MAX Prior Period based on LastDate return value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734325#M1919</link>
      <description>&lt;P&gt;Please let me know if this link does not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://onedrive.live.com/?authkey=%21ANQYX5UCHJaHyuU&amp;amp;id=E1D90AB70FBCB9DF%21805&amp;amp;cid=E1D90AB70FBCB9DF" target="_blank"&gt;https://onedrive.live.com/?authkey=%21ANQYX5UCHJaHyuU&amp;amp;id=E1D90AB70FBCB9DF%21805&amp;amp;cid=E1D90AB70FBCB9DF&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You'll be able to see several examples of how it does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Respectfully,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Robert&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 15:15:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734325#M1919</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-08T15:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: MAX Prior Period based on LastDate return value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734391#M1923</link>
      <description>&lt;P&gt;OK. Here's a solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;You have to always know what you're slicing by. You always should slice by the attributes of dimensions, not those of the fact table. The above works because Year comes from DimDates, not your fact table. I'd suggest you hide all the attributes of the fact table save the measures.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the measures you see above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Darek - Most Recent Date = 
var __onlyOneTickerVisible = HASONEFILTER( DimBenchmark[Benchmark Ticker] )
var __result = MAX( Benchmarks_PowerBI[Date] )
return
    if( __onlyOneTickerVisible, __result )&lt;/PRE&gt;&lt;PRE&gt;Darek - Most Recent Date Shifted = 
var __onlyOneTickerVisible = HASONEFILTER( DimBenchmark[Benchmark Ticker] )
var __oneShiftVisible = HASONEFILTER( 'Shift From Base Year'[Shift in Years] )
var __numOfYearsBack = SELECTEDVALUE( 'Shift From Base Year'[Shift] )
var __result =
    CALCULATE(
        [Darek - Most Recent Date],
        DATEADD( DimDate[Date], -__numOfYearsBack, YEAR )
    )
return
    if( __onlyOneTickerVisible &amp;amp;&amp;amp; __oneShiftVisible, __result )&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Darek - Most Recent Price = 
var __onlyOneTickerVisible = HASONEFILTER( DimBenchmark[Benchmark Ticker] )&lt;BR /&gt;-- In the current date context get the latest price visible
var __result = LASTNONBLANK( Benchmarks_PowerBI[ Price ], Benchmarks_PowerBI[ Price ] )
return
    if( __onlyOneTickerVisible, __result )&lt;/PRE&gt;&lt;PRE&gt;Darek - Most Recent Price Shifted = 
var __onlyOneTickerVisible = HASONEFILTER( DimBenchmark[Benchmark Ticker] )
var __oneShiftVisible = HASONEFILTER( 'Shift From Base Year'[Shift in Years] )
var __shiftInYears = SELECTEDVALUE( 'Shift From Base Year'[Shift] )
var __price =
    CALCULATE(
        [Darek - Most Recent Price],
        DATEADD( DimDate[Date], -__shiftInYears, YEAR )
    )
return
    if( __onlyOneTickerVisible &amp;amp;&amp;amp; __oneShiftVisible, __price )&lt;/PRE&gt;&lt;P&gt;All the other measures can be deleted from your file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, here's what you have to do:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Mark your DimDate table as DATE TABLE.&lt;/LI&gt;&lt;LI&gt;Create a table that will hold shifts.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Here's how you mark a table as date table. Go to Modeling&amp;nbsp; &amp;gt; Calendars and while your DimTable is displayed in the table view mode, click on Mark as Date Table.&lt;/P&gt;&lt;P&gt;2. Create a table like this:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Hide Shift (it's for calculation only) and leave the other one to be used on a slicer. Do not connect the table to anything else. It's a parameter table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Never, ever select dates from your fact table. Only from your Date dimension. Then everything will work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By the way, if you put quarters (from your Date table) in the slicer for Years, it should also work. Basically, for any selection of attribute in the DimDate dimension, it should work. Of course, on condition that I've understood the logic correctly. But you've got a good start, so you might want to adjust it to your needs if it acts up :)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Darek&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 16:42:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734391#M1923</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-08T16:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: MAX Prior Period based on LastDate return value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734407#M1927</link>
      <description>&lt;P&gt;Hi Darek,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I sincerely apprecaite your time and explanation, it will not only be helpful to myself but others whom are searching the boards for a solution as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Respectfully,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 17:00:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734407#M1927</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-08T17:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: MAX Prior Period based on LastDate return value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734416#M1928</link>
      <description>&lt;P&gt;There's a mistake in one of the formulas...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please change it to this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Darek - Most Recent Price = 
var __onlyOneTickerVisible = HASONEFILTER( DimBenchmark[Benchmark Ticker] )
var __mostRecentDate = [Darek - Most Recent Date]
var __result =
    CALCULATE(
        VALUES( Benchmarks_PowerBI[ Price ] ),
        KEEPFILTERS( DimDate[Date] = __mostRecentDate )
    )
return
-- In the current date context get the latest price visible
    if( __onlyOneTickerVisible, __result )&lt;/PRE&gt;&lt;P&gt;Sorry. We can't use LASTNONBLANK in this case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Darek&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 17:19:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/MAX-Prior-Period-based-on-LastDate-return-value/m-p/734416#M1928</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-08T17:19:46Z</dc:date>
    </item>
  </channel>
</rss>

