<?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 DAX_Subtract the Cumulative Used amount from the earliest Delivery Date's Amount (Ordered) in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Subtract-the-Cumulative-Used-amount-from-the-earliest/m-p/3988204#M154610</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Could you let me know the DAX which matches condition below?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;### Requirements:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1. **Subtract the &lt;STRONG&gt;Cumulative Used&lt;/STRONG&gt; amount starting from the earliest &lt;STRONG&gt;Delivery Date's Amount (Ordered)&lt;/STRONG&gt;**.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. **If the subtracted amount is greater than the &lt;STRONG&gt;Amount (Ordered)&lt;/STRONG&gt;**&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- Display the &lt;STRONG&gt;Amount (Ordered)&lt;/STRONG&gt; in the&lt;STRONG&gt; Amount (Used)&lt;/STRONG&gt; column.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- Subtract the remaining amount from the next earliest &lt;STRONG&gt;Delivery Date's Amount (Ordered)&lt;/STRONG&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- If the result is not greater than the &lt;STRONG&gt;Amount (Ordered)&lt;/STRONG&gt;, display the r&lt;U&gt;emaining amount&lt;/U&gt; in the &lt;STRONG&gt;Amount (Used)&lt;/STRONG&gt; column.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Sincerely,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Kim,Boram&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jun 2024 09:40:40 GMT</pubDate>
    <dc:creator>BORAMKIM</dc:creator>
    <dc:date>2024-06-12T09:40:40Z</dc:date>
    <item>
      <title>DAX_Subtract the Cumulative Used amount from the earliest Delivery Date's Amount (Ordered)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Subtract-the-Cumulative-Used-amount-from-the-earliest/m-p/3988204#M154610</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Could you let me know the DAX which matches condition below?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;### Requirements:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1. **Subtract the &lt;STRONG&gt;Cumulative Used&lt;/STRONG&gt; amount starting from the earliest &lt;STRONG&gt;Delivery Date's Amount (Ordered)&lt;/STRONG&gt;**.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. **If the subtracted amount is greater than the &lt;STRONG&gt;Amount (Ordered)&lt;/STRONG&gt;**&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- Display the &lt;STRONG&gt;Amount (Ordered)&lt;/STRONG&gt; in the&lt;STRONG&gt; Amount (Used)&lt;/STRONG&gt; column.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- Subtract the remaining amount from the next earliest &lt;STRONG&gt;Delivery Date's Amount (Ordered)&lt;/STRONG&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- If the result is not greater than the &lt;STRONG&gt;Amount (Ordered)&lt;/STRONG&gt;, display the r&lt;U&gt;emaining amount&lt;/U&gt; in the &lt;STRONG&gt;Amount (Used)&lt;/STRONG&gt; column.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Sincerely,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Kim,Boram&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2024 09:40:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Subtract-the-Cumulative-Used-amount-from-the-earliest/m-p/3988204#M154610</guid>
      <dc:creator>BORAMKIM</dc:creator>
      <dc:date>2024-06-12T09:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: DAX_Subtract the Cumulative Used amount from the earliest Delivery Date's Amount (Ordered)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Subtract-the-Cumulative-Used-amount-from-the-earliest/m-p/3989767#M154707</link>
      <description>&lt;P&gt;Please provide sample data that covers your issue or question &lt;STRONG&gt;completely&lt;/STRONG&gt;, in a &lt;STRONG&gt;usable&lt;/STRONG&gt; format (not as a screenshot).&lt;BR /&gt;&lt;BR /&gt;Do not include sensitive information or anything not related to the issue or question. &lt;BR /&gt;&lt;BR /&gt;If you are unsure how to upload data please refer to &lt;A href="https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;Please show the expected outcome based on the sample data you provided. &lt;BR /&gt;&lt;BR /&gt;Want faster answers? &lt;A href="https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 00:52:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Subtract-the-Cumulative-Used-amount-from-the-earliest/m-p/3989767#M154707</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-06-13T00:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: DAX_Subtract the Cumulative Used amount from the earliest Delivery Date's Amount (Ordered)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Subtract-the-Cumulative-Used-amount-from-the-earliest/m-p/3989888#M154717</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thanks for the detailed explanation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to substract the values based on one column to another columns.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Could you let me know the DAX which matches condition below?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A title="DAX Query" href="https://docs.google.com/spreadsheets/d/12rjyVZ074RieoY6CstZLXe44vHZ_gYF5/edit?usp=sharing&amp;amp;ouid=109226985489688781015&amp;amp;rtpof=true&amp;amp;sd=true" target="_self"&gt;DAX Query.xlsx&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;* Requirements:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1. **Subtract the&amp;nbsp;&lt;STRONG&gt;Cumulative Used&lt;/STRONG&gt;&amp;nbsp;amount starting from the earliest&amp;nbsp;&lt;STRONG&gt;Delivery Date's Amount (Ordered)&lt;/STRONG&gt;**.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. **If the subtracted amount is greater than the&amp;nbsp;&lt;STRONG&gt;Amount (Ordered)&lt;/STRONG&gt;**&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- Display the&amp;nbsp;&lt;STRONG&gt;Amount (Ordered)&lt;/STRONG&gt;&amp;nbsp;in the&lt;STRONG&gt;&amp;nbsp;Amount (Used)&lt;/STRONG&gt;&amp;nbsp;column.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- Subtract the remaining amount from the next earliest&amp;nbsp;&lt;STRONG&gt;Delivery Date's Amount (Ordered)&lt;/STRONG&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- If the result is not greater than the&amp;nbsp;&lt;STRONG&gt;Amount (Ordered)&lt;/STRONG&gt;, display the r&lt;U&gt;emaining amount&lt;/U&gt;&amp;nbsp;in the&amp;nbsp;&lt;STRONG&gt;Amount (Used)&lt;/STRONG&gt;&amp;nbsp;column.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;[Table1]&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;Delivery Date&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;[Amount (Ordered)&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Amount (Used)&amp;nbsp;&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022-03-30&lt;/TD&gt;&lt;TD&gt;984,249&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2023-04-12&lt;/TD&gt;&lt;TD&gt;29,559,965&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2024-05-21&lt;/TD&gt;&lt;TD&gt;10,187,488&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;[Table2]&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Cumulative Used&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;18,719,345&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;U&gt;&lt;FONT face="arial black,avant garde"&gt;**Result&amp;nbsp;&lt;/FONT&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;[Table1]&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;Delivery Date&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;[Amount (Ordered)&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Amount (Used)&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022-03-30&lt;/TD&gt;&lt;TD&gt;984,249&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;984,249&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2023-04-12&lt;/TD&gt;&lt;TD&gt;29,559,965&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;17,735,093&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2024-05-21&lt;/TD&gt;&lt;TD&gt;10,187,488&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you in advance.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 04:42:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Subtract-the-Cumulative-Used-amount-from-the-earliest/m-p/3989888#M154717</guid>
      <dc:creator>BORAMKIM</dc:creator>
      <dc:date>2024-06-13T04:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: DAX_Subtract the Cumulative Used amount from the earliest Delivery Date's Amount (Ordered)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Subtract-the-Cumulative-Used-amount-from-the-earliest/m-p/3994038#M155055</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "NcnBDcAwCASwXXgfEhzQwixR9l8jUaX667WERqqFhglkOsEc2fgi1FKdNzioGsxT/6VaKf2eG7xfZLfsfQA=",
          BinaryEncoding.Base64
        ),
        Compression.Deflate
      )
    ),
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [#"Delivery Date" = _t, #"Amount#(lf)(Ordered)" = _t]
  ),
  #"Changed Type" = Table.TransformColumnTypes(
    Source,
    {{"Delivery Date", type date}, {"Amount#(lf)(Ordered)", Currency.Type}}
  ),
  #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
  #"Added Custom" = Table.AddColumn(
    #"Added Index",
    "Amount (Used)",
    each List.Accumulate(
      {0 .. [Index]},
      [cm = Table2[Cumulative Used]{0}, rs = 0],
      (state, current) =&amp;gt; [
        rs =
          if #"Added Index"[#"Amount#(lf)(Ordered)"]{current} &amp;lt; state[cm] then
            #"Added Index"[#"Amount#(lf)(Ordered)"]{current}
          else
            state[cm],
        cm =
          if #"Added Index"[#"Amount#(lf)(Ordered)"]{current} &amp;lt; state[cm] then
            state[cm] - #"Added Index"[#"Amount#(lf)(Ordered)"]{current}
          else
            0
      ]
    )
  ),
  #"Expanded Amount (Used)" = Table.ExpandRecordColumn(
    #"Added Custom",
    "Amount (Used)",
    {"rs"},
    {"Amount (Used).rs"}
  ),
  #"Changed Type1" = Table.TransformColumnTypes(
    #"Expanded Amount (Used)",
    {{"Amount (Used).rs", Currency.Type}}
  )
in
  #"Changed Type1"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or if you want it in DAX:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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;LI-CODE lang="markup"&gt;Used Column = 
var d = [Delivery Date]
var cu = sumx(Table2,[Cumulative Used])
var c2 = sumx(filter(Table1,[Delivery Date]&amp;lt;d),[Amount(Ordered)])
var c = c2+[Amount(Ordered)]
return if (c&amp;lt;cu,c,max(0,cu-c2))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2024 00:47:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Subtract-the-Cumulative-Used-amount-from-the-earliest/m-p/3994038#M155055</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-06-15T00:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: DAX_Subtract the Cumulative Used amount from the earliest Delivery Date's Amount (Ordered)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Subtract-the-Cumulative-Used-amount-from-the-earliest/m-p/3997797#M155477</link>
      <description>&lt;P&gt;&lt;SPAN&gt;The code you provided was a great help to me&amp;nbsp;and it works well.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thank you very much !&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":handshake:"&gt;🤝&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 08:24:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Subtract-the-Cumulative-Used-amount-from-the-earliest/m-p/3997797#M155477</guid>
      <dc:creator>BORAMKIM</dc:creator>
      <dc:date>2024-06-18T08:24:12Z</dc:date>
    </item>
  </channel>
</rss>

