Forum Discussion
peterpan
2 years agoHelper I
Amount Adjustment on FIFO basis
I have two tables. Table A- Invoice Number Amount 4001 50000 4002 60000 4003 95000 4002 2000 Table B- Invoice Number Invoice Item Invoice Amount 4001 18 30000 4...
Fowmy
2 years agoSuper User
peterpan
I know you have posted this question under Power Query but I would like to see if you are interested in a DAX solution, if so, add a calculated column in Table B, using the code below :
Amount Paid =
VAR __InvNum = 'Table B'[Invoice Number]
VAR __InvItem = 'Table B'[Invoice Item]
VAR __InvAmount = 'Table B'[Invoice Amount]
VAR __TotalPayment = SUMX( FILTER( 'Table A' , 'Table A'[Invoice Number] = __InvNum ) , 'Table A'[Amount] )
VAR __CumAmount = SUMX( FILTER( 'Table B' , 'Table B'[Invoice Number] = __InvNum && 'Table B'[Invoice Item] <= __InvItem ) , 'Table B'[Invoice Amount] )
VAR __RemAmount = __TotalPayment - __CumAmount
RETURN
IF( __RemAmount >= 0 , __InvAmount , MAX( 0, __InvAmount + __RemAmount ) )
Output: