As you can see from my Purchase_table, I have an item (no. 23), which has been purchased 3 times.
The total QTY bought is 1650(1000+50+600).
Now in another fact table(which also include sale) I calculate units in stock on a certain date with the measure below.
Now if we imagine that 30-06-2019 there is 800 left of the total QTY bought(1650). According to FIFO this is 600 from 20-06-2019, 50 from 18-05-2019 and 150 from 23-04-2019(1000 was bought, 850 of this has been sold afterwards)
How can I make a measure which returns the following from my purchase tabel?
Itemnumber Date QTY bought Qty_Stock
23 20-06-2019 600 600
23 18-05-2019 50 50
23 23-04-2019 1000 150
UnitsInStock:= IF ( MIN ( 'DIM_Time'[DateValue] ) <= CALCULATE ( MAX ( 'Fact_Inventory'[PostingDate] ); ALL ( 'Fact_Inventory' ) ); CALCULATE ( SUM ( 'Fact_Inventory'[Quantity] ); FILTER ( ALL( 'DIM_Time'[DateValue]); 'DIM_Time'[DateValue] <= MAX ( 'DIM_Time'[DateValue] ) ) ) )