<?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 Add current value column by subtracting  current row from previous row in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-current-value-column-by-subtracting-current-row-from/m-p/2460021#M66548</link>
    <description>&lt;P&gt;Dear PBI Community, thank you in advance for the help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to Power BI &amp;amp; DAX&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have tow tables &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;1) flock table with an initial number of birds&lt;/STRONG&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2) Birds mortality logs&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I want to add new colum in mortality log table wich gives the current birds count by subtracting previous mortality&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 17 Apr 2022 06:35:49 GMT</pubDate>
    <dc:creator>AHMEDMARHOON</dc:creator>
    <dc:date>2022-04-17T06:35:49Z</dc:date>
    <item>
      <title>Add current value column by subtracting  current row from previous row</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-current-value-column-by-subtracting-current-row-from/m-p/2460021#M66548</link>
      <description>&lt;P&gt;Dear PBI Community, thank you in advance for the help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to Power BI &amp;amp; DAX&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have tow tables &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;1) flock table with an initial number of birds&lt;/STRONG&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2) Birds mortality logs&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I want to add new colum in mortality log table wich gives the current birds count by subtracting previous mortality&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Apr 2022 06:35:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-current-value-column-by-subtracting-current-row-from/m-p/2460021#M66548</guid>
      <dc:creator>AHMEDMARHOON</dc:creator>
      <dc:date>2022-04-17T06:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: Add current value column by subtracting  current row from previous row</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-current-value-column-by-subtracting-current-row-from/m-p/2460213#M66553</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="378898" data-lia-user-login="AHMEDMARHOON" class="lia-mention lia-mention-user"&gt;AHMEDMARHOON&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to do it using DAX, you can first create a one to many relationship between the two tables based on flock id in both tables (that will make it much faster and easier)&lt;/P&gt;&lt;P&gt;the create &lt;STRONG&gt;New Column&lt;/STRONG&gt; &amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Balance No. of Birds =
VAR CurrentID = Mortality[id]
VAR FlockTable =
    CALCULATETABLE ( Motality, ALLEXCEPT ( Mortalit, Mortalit[flock_id] ) )
VAR PreviousIDsTable =
    FILTER ( FlockTable, Mortality[id] &amp;lt;= CurrentID )
VAR TotalMortality =
    SUMX ( PreviousIDsTable, Mortality[mortality] )
VAR FlockPopulation =
    RELATED ( Flocks[no_of_birds] )
RETURN
    FlockPopulation - TotalMortality&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Apr 2022 12:28:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-current-value-column-by-subtracting-current-row-from/m-p/2460213#M66553</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-04-17T12:28:30Z</dc:date>
    </item>
  </channel>
</rss>

