title: DAX : Allocate Inventory to Open Orders
body: <p>I am trying to allocate inventory items to open orders in DAX, PowerBi. The idea is to allocate all the available inventory to the oldest order first, then allocate the remaining inventory to the second oldest, etc. until the inventory is depleted. The inventory can be depleted even if the open order is not completely satisfied. </p>
  
  <p>Please check the attached picture as an example for the allocations below</p>
  
  <p><img src="https://i.stack.imgur.com/Bq97d.png" alt="Allocation Example"></p>
  
  <p>I tried adding a column in the open order table using the Calculate function but the results were not correct at all. It didn't do any allocations, it just summed up the inventory. </p>
  
  <pre><code>CALCULATE (
          [QOH],
          FILTER (
              ALL ( 'Open Orders'[Parent Name] ),
              'Open Orders'[Due Date] &lt;= MAX ( ( 'Open Orders'[Due Date] ) )
          )
      )
  </code></pre>