Forum Discussion
FIFO Quantity by Transfer Order
- 6 years ago
alexricker0928 you can try this code, it might help you.
FIFO := VAR _QTY = CALCULATE ( SUM ( Data[Transfer Qty] ) ) VAR _CurrentDate = MAX ( Data[Date] ) VAR _CurrentSO = MAX ( Data[Transfer/Sales Order #] ) VAR _CurrentItem = VALUES ( Data[ItemId] ) VAR _CurrentBalance = CALCULATE ( SUM ( Data[Transfer Qty] ), FILTER ( ALL ( Data ), Data[ItemId] IN _CurrentItem && ( Data[Transfer/Sales Order #] <= _CurrentSO && Data[Date] <= _CurrentDate || Data[Transfer Qty] < 0 ) ) ) RETURN IF ( _CurrentBalance > 0 && _QTY > 0, MIN ( _CurrentBalance, _QTY ) )
alexricker0928 you can try this code, it might help you.
FIFO :=
VAR _QTY =
CALCULATE ( SUM ( Data[Transfer Qty] ) )
VAR _CurrentDate =
MAX ( Data[Date] )
VAR _CurrentSO =
MAX ( Data[Transfer/Sales Order #] )
VAR _CurrentItem =
VALUES ( Data[ItemId] )
VAR _CurrentBalance =
CALCULATE (
SUM ( Data[Transfer Qty] ),
FILTER (
ALL ( Data ),
Data[ItemId] IN _CurrentItem
&& ( Data[Transfer/Sales Order #] <= _CurrentSO
&& Data[Date] <= _CurrentDate
|| Data[Transfer Qty] < 0 )
)
)
RETURN
IF ( _CurrentBalance > 0 && _QTY > 0, MIN ( _CurrentBalance, _QTY ) )
Hi wdx223_Daniel,
The solution you provided worked for the original data. Thank you for your response!
However, with additional data coming in, it doesn't work when the in and out qtys dont match up exactly like they did in the data I provided first. For example:
This data:
| Transaction Id | ItemId | Date | TransferQty |
| 1000-000152 | 43810 | 8/1/2020 | 10 |
| 1000-007767 | 43810 | 8/5/2020 | -3 |
| 1000-000153 | 43810 | 8/8/2020 | 10 |
| 1000-007768 | 43810 | 8/10/2020 | -5 |
| 1000-000076 | 43810 | 10/5/2020 | 1 |
| 1000-000071 | 43810 | 10/5/2020 | 2 |
| 1000-002647 | 43810 | 10/5/2020 | -2 |
| 1000-000072 | 43810 | 10/5/2020 | 1 |
| 1000-000074 | 43810 | 10/5/2020 | 1 |
| 1000-007767 | 43810 | 10/20/2020 | 3 |
| 1000-007767 | 43810 | 10/20/2020 | -3 |
I would expect to see this in the PBI table using FIFO logic:
| Transaction Id | ItemId | Date | FIFO |
| 1000-000153 | 43810 | 8/8/2020 | 7 |
| 1000-000076 | 43810 | 10/5/2020 | 1 |
| 1000-000071 | 43810 | 10/5/2020 | 2 |
| 1000-000072 | 43810 | 10/5/2020 | 1 |
| 1000-000074 | 43810 | 10/5/2020 | 1 |
| 1000-007767 | 43810 | 10/20/2020 | 3 |
This is what shows currently in the PBI table given your original solution:
| Transaction Id | ItemId | Date | FIFO |
| 1000-000153 | 43810 | 8/8/2020 | 7 |
Which is technically correct, but I also want to see any transactions and their quantities after that, that have not been affected by negative quantities.
Do you have any idea what needs to be added to your original code to help solve the problem?
- wdx223_Daniel6 years ago
Community Champion
alexricker0928 i think the basic assumption is Transfer/Sales Order is a series of numbers which is cumulatively growing, not random. so if you change the sample data like that, the measure get a right result