<?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: Percent Return for last 5 trading days (Base Price as of Earliest Date) in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Percent-Return-for-last-5-trading-days-Base-Price-as-of-Earliest/m-p/2610879#M75728</link>
    <description>&lt;P&gt;Thank you for the quick reponse, and the good idea on FirstNonBlankValue.&amp;nbsp; I tweaked the solution a bit to accomodate to my data layout as follow:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;calculate(firstnonblankvalue(Table[Date], &lt;FONT color="#0000FF"&gt;[PxCurrent]&lt;/FONT&gt;), &lt;FONT color="#0000FF"&gt;allexcept(Table,[Ticker])&lt;/FONT&gt;)&lt;/SPAN&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The resulting table looks like this:&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;img /&gt;&lt;/DIV&gt;&lt;P&gt;For any one out there looking for this solution, please see code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PxChg.L5d = 
VAR MaxIndex = CALCULATE( MAX(IndexETF_L2Y[Index]), ALLEXCEPT(IndexETF_L2Y,IndexETF_L2Y[Ticker]) ) 
VAR CurIndex = CALCULATE( MIN(IndexETF_L2Y[Index]), ALLEXCEPT(IndexETF_L2Y, IndexETF_L2Y[Ticker], IndexETF_L2Y[Date.Index]) ) 
VAR Period = 5  //Adjust for different lookback period
VAR Counter = MaxIndex - Period
VAR CurPx = CALCULATE( SUM(IndexETF_L2Y[Close]), FILTER(IndexETF_L2Y, MIN(IndexETF_L2Y[Index]) &amp;gt;= Counter) ) 
VAR BasePx = CALCULATE( FIRSTNONBLANKVALUE(IndexETF_L2Y[Date.Index], 
                IF(MIN(IndexETF_L2Y[Index]) &amp;gt;= Counter, SUM(IndexETF_L2Y[Close]))), 
                ALLEXCEPT(IndexETF_L2Y,IndexETF_L2Y[Ticker])
            ) 
RETURN   
IF( MIN(IndexETF_L2Y[Index]) &amp;gt;= Counter,
    DIVIDE( CurPx, BasePx ) - 1
)    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks again, amitchandak.&amp;nbsp; Will subscribed and like your youtube channel.&amp;nbsp; Grateful!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jun 2022 08:14:57 GMT</pubDate>
    <dc:creator>ALC9816</dc:creator>
    <dc:date>2022-06-30T08:14:57Z</dc:date>
    <item>
      <title>Percent Return for last 5 trading days (Base Price as of Earliest Date)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Percent-Return-for-last-5-trading-days-Base-Price-as-of-Earliest/m-p/2608277#M75555</link>
      <description>&lt;P&gt;How can I make PxBase (base price) the same for all cells (according to earliest day price)&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;In Tableau, I would do this.&amp;nbsp; How do I do it in Power Bi?&lt;BR /&gt;&amp;nbsp;{ FIXED [Ticker] : SUM( IF [Date.Index] = [MinDate] THEN SUM([Close) END) }&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;My current measure formula are as below.&amp;nbsp; The raw date range is from 2020 to 2022, thus I created an index column in the table to calculate the last 5 trading days for each ticker (dates are non-continious due to weekends and holidays in different stock markets).&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PxCurrent = 
VAR MaxIndex = CALCULATE( MAX(IndexETF_L2Y[Index]), ALLEXCEPT(IndexETF_L2Y,IndexETF_L2Y[Ticker]) ) 
VAR CurIndex = CALCULATE( MIN(IndexETF_L2Y[Index]), ALLEXCEPT(IndexETF_L2Y, IndexETF_L2Y[Ticker], IndexETF_L2Y[Date.Index]) ) 
VAR Period = 5
VAR Counter = MaxIndex - CurIndex 
VAR CurPx     = CALCULATE( SUM(IndexETF_L2Y[Close]), FILTER(IndexETF_L2Y, Counter &amp;lt;= Period) ) 
RETURN
    CurPx&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PxBase = 
VAR MaxIndex = CALCULATE( MAX(IndexETF_L2Y[Index]), ALLEXCEPT(IndexETF_L2Y,IndexETF_L2Y[Ticker]) ) 
VAR CurIndex = CALCULATE( MIN(IndexETF_L2Y[Index]), ALLEXCEPT(IndexETF_L2Y, IndexETF_L2Y[Ticker], IndexETF_L2Y[Date.Index]) ) 
VAR Period = 5
VAR Counter = (MaxIndex - CurIndex)
VAR StartPx   = CALCULATE( SUM(IndexETF_L2Y[Close]), FILTER(IndexETF_L2Y, Counter = Period) )
RETURN
    StartPx&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Ultimately, I want to divide PxCurrent / PxBase - 1 in order to get to the last 5 days percent change (pegged to starting date) chart like this:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Grateful for any Power Bi Master's help.&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 03:56:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Percent-Return-for-last-5-trading-days-Base-Price-as-of-Earliest/m-p/2608277#M75555</guid>
      <dc:creator>ALC9816</dc:creator>
      <dc:date>2022-06-29T03:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Return for last 5 trading days (Base Price as of Earliest Date)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Percent-Return-for-last-5-trading-days-Base-Price-as-of-Earliest/m-p/2609131#M75617</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="406842" data-lia-user-login="ALC9816" class="lia-mention lia-mention-user"&gt;ALC9816&lt;/a&gt; , if 5 days data is already filtered and PX base is a measure &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;calculate(firstnonblankvalue(Table[Date], [PxBase]), allselected(Table))&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 10:08:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Percent-Return-for-last-5-trading-days-Base-Price-as-of-Earliest/m-p/2609131#M75617</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2022-06-29T10:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Return for last 5 trading days (Base Price as of Earliest Date)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Percent-Return-for-last-5-trading-days-Base-Price-as-of-Earliest/m-p/2610879#M75728</link>
      <description>&lt;P&gt;Thank you for the quick reponse, and the good idea on FirstNonBlankValue.&amp;nbsp; I tweaked the solution a bit to accomodate to my data layout as follow:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;calculate(firstnonblankvalue(Table[Date], &lt;FONT color="#0000FF"&gt;[PxCurrent]&lt;/FONT&gt;), &lt;FONT color="#0000FF"&gt;allexcept(Table,[Ticker])&lt;/FONT&gt;)&lt;/SPAN&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The resulting table looks like this:&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;img /&gt;&lt;/DIV&gt;&lt;P&gt;For any one out there looking for this solution, please see code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PxChg.L5d = 
VAR MaxIndex = CALCULATE( MAX(IndexETF_L2Y[Index]), ALLEXCEPT(IndexETF_L2Y,IndexETF_L2Y[Ticker]) ) 
VAR CurIndex = CALCULATE( MIN(IndexETF_L2Y[Index]), ALLEXCEPT(IndexETF_L2Y, IndexETF_L2Y[Ticker], IndexETF_L2Y[Date.Index]) ) 
VAR Period = 5  //Adjust for different lookback period
VAR Counter = MaxIndex - Period
VAR CurPx = CALCULATE( SUM(IndexETF_L2Y[Close]), FILTER(IndexETF_L2Y, MIN(IndexETF_L2Y[Index]) &amp;gt;= Counter) ) 
VAR BasePx = CALCULATE( FIRSTNONBLANKVALUE(IndexETF_L2Y[Date.Index], 
                IF(MIN(IndexETF_L2Y[Index]) &amp;gt;= Counter, SUM(IndexETF_L2Y[Close]))), 
                ALLEXCEPT(IndexETF_L2Y,IndexETF_L2Y[Ticker])
            ) 
RETURN   
IF( MIN(IndexETF_L2Y[Index]) &amp;gt;= Counter,
    DIVIDE( CurPx, BasePx ) - 1
)    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks again, amitchandak.&amp;nbsp; Will subscribed and like your youtube channel.&amp;nbsp; Grateful!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 08:14:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Percent-Return-for-last-5-trading-days-Base-Price-as-of-Earliest/m-p/2610879#M75728</guid>
      <dc:creator>ALC9816</dc:creator>
      <dc:date>2022-06-30T08:14:57Z</dc:date>
    </item>
  </channel>
</rss>

