<?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: calculate current week data using current week and previous week info in DAX in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-current-week-data-using-current-week-and-previous-week/m-p/2548050#M72021</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for the response. I am trying to replicate this but getting an error with EARLIER function.&amp;nbsp;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 May 2022 14:31:23 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-05-30T14:31:23Z</dc:date>
    <item>
      <title>calculate current week data using current week and previous week info in DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-current-week-data-using-current-week-and-previous-week/m-p/2547554#M71985</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I hope everyone's well.&lt;/P&gt;&lt;P&gt;I am trying to create a measure that uses previous week and current week data. The table looks like the following-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN&gt;week_end&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD&gt;profit&lt;/TD&gt;&lt;TD&gt;loss&lt;/TD&gt;&lt;TD&gt;reference_for_1_may&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;net_product_margin&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;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to create a measure net_product_margin which is calculated by using last week's net_product_margin value - current week 'loss' + current week 'gain'. Here's the code that I tried but it doesn't work perfectly. This does calculate the net_product_margin value correctly for 8th May 2022 but since I am using the column reference_for_1_may it doesn't calculate the later week net_product_margin value correctly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;net_product_margin = var _lastweek = CALCULATE('All Measures'[reference_for_1_may], FILTER(ALL('Dim_Date'),'Dim_Date'[End_of_Week] = SELECTEDVALUE(Dim_Date[End_of_Week]) -7 )) RETURN _lastweek - 'All Measures'[loss] + 'All Measures'[profit]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is how the formula looks in excel.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;img /&gt;&lt;img /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have the data from 1st May 2022 in my table so to have a reference I have added a reference column called reference_for_1_may that acts as reference data to calculate later week net_product_margin. I am scratching my head on this. Any help would be much appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2022 10:24:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-current-week-data-using-current-week-and-previous-week/m-p/2547554#M71985</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-05-30T10:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: calculate current week data using current week and previous week info in DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-current-week-data-using-current-week-and-previous-week/m-p/2547953#M72015</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Here is the sample file with the solution&amp;nbsp;&lt;A href="https://www.dropbox.com/t/6o38jT13uTKnx2Fh" target="_blank"&gt;https://www.dropbox.com/t/6o38jT13uTKnx2Fh&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;New Column&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;net_product_margin_calculated = 
VAR ReferenceValue = 342335
VAR FirstDateEver = MIN ( 'P&amp;amp;L'[week_end] )
RETURN
    SUMX ( 
        FILTER ( 
            'P&amp;amp;L', 
            'P&amp;amp;L'[week_end] &amp;lt;= EARLIER ( 'P&amp;amp;L'[week_end] ) 
                &amp;amp;&amp;amp; 'P&amp;amp;L'[week_end] &amp;gt; FirstDateEver
        ), 
        'P&amp;amp;L'[profit] - 'P&amp;amp;L'[loss]
    ) 
    + ReferenceValue&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 30 May 2022 13:42:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-current-week-data-using-current-week-and-previous-week/m-p/2547953#M72015</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-05-30T13:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: calculate current week data using current week and previous week info in DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-current-week-data-using-current-week-and-previous-week/m-p/2548050#M72021</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for the response. I am trying to replicate this but getting an error with EARLIER function.&amp;nbsp;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2022 14:31:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-current-week-data-using-current-week-and-previous-week/m-p/2548050#M72021</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-05-30T14:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: calculate current week data using current week and previous week info in DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-current-week-data-using-current-week-and-previous-week/m-p/2548052#M72022</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The solution is based on a calculated column not a measure&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2022 14:32:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-current-week-data-using-current-week-and-previous-week/m-p/2548052#M72022</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-05-30T14:32:48Z</dc:date>
    </item>
  </channel>
</rss>

