<?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: Recursion/Self referencing &amp;amp; year-to-date attribution effect in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-Self-referencing-amp-year-to-date-attribution-effect/m-p/3844521#M150274</link>
    <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My apologies. I did not include the row numbers in the sample data. I edited this now. Column G is just to clarify how I calculate Column F. I want to write a dax code that calculates Column F.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Apr 2024 08:03:28 GMT</pubDate>
    <dc:creator>JoeriT</dc:creator>
    <dc:date>2024-04-17T08:03:28Z</dc:date>
    <item>
      <title>Recursion/Self referencing &amp; year-to-date attribution effect</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-Self-referencing-amp-year-to-date-attribution-effect/m-p/3841502#M150176</link>
      <description>&lt;P&gt;Hello Fabric Community,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I hope you're all doing well! I'm currently working on a project where I need to calculate the year-to-date cumulative attribution effect for investment portfolio analysis in Power BI, and I've encountered a bit of a roadblock.&lt;/P&gt;&lt;P&gt;Here's a breakdown of the problem:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have a formula that calculates the Year-to-date cumulative attribution effect:&lt;/P&gt;&lt;P&gt;Ei' = (Ei-1')(1+BRi/100) + (Ei)(1+PRi-1'/100)&lt;/P&gt;&lt;P&gt;where:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Ei' is the cumulative attribution effect through period i.&lt;/LI&gt;&lt;LI&gt;Ei-1' is the cumulative attribution effect in period i-1.&lt;/LI&gt;&lt;LI&gt;BRi is the benchmark return in period i.&lt;/LI&gt;&lt;LI&gt;Ei is the attribution effect in period i.&lt;/LI&gt;&lt;LI&gt;PRi-1' is the cumulative portfolio return through period i-1.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Note that on the 1st of January no historical data should be used in this formula (even though the dataset contains data from multiple years):&lt;BR /&gt;&lt;BR /&gt;Ei' = (0)(1+BRi/100) + (Ei)(1+0/100)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thus on January 1st:&lt;/P&gt;&lt;P&gt;Ei' = Ei&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I find it difficult to implement the logic correctly, particularly the self-referencing. I read in other posts that a work-around for self-referencing in formulas is to make the formula closed-form. Could anyone provide guidance on the possibility of making this formula closed form and if possible, how to write a code for this formula that works in DAX?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Below you find some sample data and in column G the excel calculation for this formula.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;G&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;Date&lt;/TD&gt;&lt;TD&gt;Port. Total Return&lt;/TD&gt;&lt;TD&gt;Cumu. Port. Total Return&lt;/TD&gt;&lt;TD&gt;Bench. Total Return&lt;/TD&gt;&lt;TD&gt;Attribution effect&lt;/TD&gt;&lt;TD&gt;Cumulative attribution effect&lt;/TD&gt;&lt;TD&gt;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-2024&lt;/TD&gt;&lt;TD&gt;-0,02&lt;/TD&gt;&lt;TD&gt;-1,098&lt;/TD&gt;&lt;TD&gt;-0,003&lt;/TD&gt;&lt;TD&gt;-0,02&lt;/TD&gt;&lt;TD&gt;0,00814329&lt;/TD&gt;&lt;TD&gt;‘=F5*(1+D6/100)+E6*(1+C5/100)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;6-1-2024&lt;/TD&gt;&lt;TD&gt;-0,252&lt;/TD&gt;&lt;TD&gt;-1,347&lt;/TD&gt;&lt;TD&gt;-0,222&lt;/TD&gt;&lt;TD&gt;-0,023&lt;/TD&gt;&lt;TD&gt;-0,01474788&lt;/TD&gt;&lt;TD&gt;‘=F6*(1+D7/100)+E7*(1+C6/100)&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Note that column G contains the excel formulas I use to calculate column F. I want to replicate the results in column F by dax code.&lt;BR /&gt;&lt;BR /&gt;Any insights or suggestions would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 07:50:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-Self-referencing-amp-year-to-date-attribution-effect/m-p/3841502#M150176</guid>
      <dc:creator>JoeriT</dc:creator>
      <dc:date>2024-04-17T07:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion/Self referencing &amp; year-to-date attribution effect</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-Self-referencing-amp-year-to-date-attribution-effect/m-p/3843841#M150260</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="707414" data-lia-user-login="JoeriT" class="lia-mention lia-mention-user"&gt;JoeriT&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I create a table as you mentioned.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Then I create a column and here is the DAX code.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Column =
VAR CurrentDate = 'Table'[Date]
VAR CurrentAttributionEffect = 'Table'[Attribution effect]
VAR CurrentBenchmarkReturn = 'Table'[Bench. Total Return]
VAR CurrentPortfolioReturn = 'Table'[Cumu. Port. Total Return]
VAR PreviousCumulativeAttributionEffect =
    CALCULATE (
        SUMX (
            FILTER ( ALL ( 'Table' ), 'Table'[Date] &amp;lt; CurrentDate ),
            'Table'[Cumulative attribution effect]
        ),
        ALL ( 'Table' )
    )
RETURN
    IF (
        CurrentDate = DATE ( YEAR ( CurrentDate ), 1, 1 ),
        CurrentAttributionEffect,
        PreviousCumulativeAttributionEffect * ( 1 + CurrentBenchmarkReturn / 100 ) + CurrentAttributionEffect * ( 1 + CurrentPortfolioReturn / 100 )
    )&lt;/LI-CODE&gt;
&lt;P&gt;Finally you can get what you want.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&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;P style="margin-bottom: 6.0pt;"&gt;&lt;SPAN&gt;Best Regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-bottom: 6.0pt;"&gt;&lt;SPAN&gt;Yilong Zhou&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-bottom: 6.0pt;"&gt;&lt;SPAN&gt;If this post&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;helps&lt;/I&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;Accept it as the solution&lt;/I&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 06:12:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-Self-referencing-amp-year-to-date-attribution-effect/m-p/3843841#M150260</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-04-17T06:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion/Self referencing &amp; year-to-date attribution effect</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-Self-referencing-amp-year-to-date-attribution-effect/m-p/3844521#M150274</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My apologies. I did not include the row numbers in the sample data. I edited this now. Column G is just to clarify how I calculate Column F. I want to write a dax code that calculates Column F.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 08:03:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-Self-referencing-amp-year-to-date-attribution-effect/m-p/3844521#M150274</guid>
      <dc:creator>JoeriT</dc:creator>
      <dc:date>2024-04-17T08:03:28Z</dc:date>
    </item>
  </channel>
</rss>

