excel

Finding the correct remaining customer term with a given goods volume


I try to find the worst remaining customer term of goods which are distributed in excel.

I have following information: Article number, Date of goods receipt, Date of remaining customer term and volume.

For the following Example: I have currently a total of 300 pieces. When I sort by the remaining customer term and substract each deliverie from my current stock my worst remaining customer term is 04.02.2025. 300 – 30 (10.02.2025) - 20 (10.02.2025) - 100 (06.02.2025) - 30 (06.02.2025) - 50 (05.02.2025) - 30 (04.02.2025) = 10 remaining pieces with Remaining Customer term of 04.02.2025.

Article Number Goods Receipt Remaining Customer Term Volume in pieces
1 04.01.2025 03.02.2025 30
1 05.01.2025 04.02.2025 30
1 06.01.2025 05.02.2025 50
1 07.01.2025 06.02.2025 30
1 07.01.2025 06.02.2025 100
1 08.01.2025 07.02.2025 30
1 31.12.2024 10.02.2025 20
1 11.01.2025 10.02.2025 30

I tried the maxif function combined with the sortby of the column remaining customer term but coudn't find the answer.


Solution

  • A draft solution to check it's on the right lines - reverse sort the list then work out running totals and do an approximate lookup to find the last one which is less than 300.

    This will need refinement to cover the case where the sum is exactly 300 and to display the remaining volume..

    =LET(sb,SORTBY(C2:D9,ROW(C2:D9),-1),
    rt,SCAN(0,TAKE(sb,,-1),SUM),
    XLOOKUP(300,rt,TAKE(sb,,1),,-1))
    

    So the whole thing with these refinements would be:

    =LET(stock,300,range,C2:D9,sb,SORTBY(range,ROW(range),-1),
    rt,SCAN(0,TAKE(sb,,-1),SUM),
    idx,XMATCH(stock,rt,-1),
    IF(INDEX(rt,idx)=stock,HSTACK(INDEX(TAKE(sb,,1),idx+1),INDEX(TAKE(sb,,-1),idx+1)),
       HSTACK(INDEX(TAKE(sb,,1),idx),stock-INDEX(rt,idx))))
    
    Article Number Goods Receipt Remaining Customer Term Volume in pieces Date Remaining vol
    1 04.01.2025 03.02.2025 30 04.02.2025 10
    1 05.01.2025 04.02.2025 30
    1 06.01.2025 05.02.2025 50
    1 07.01.2025 06.02.2025 30
    1 07.01.2025 06.02.2025 100
    1 08.01.2025 07.02.2025 30
    1 31.12.2024 10.02.2025 20
    1 11.01.2025 10.02.2025 30

    Replacing the Excel 365 functions Take, hstack and scan would give

    =LET(stock,300,range,C2:D9,sb,SORTBY(range,ROW(range),-1),
    rt,MMULT(IF(TRANSPOSE(ROW(A1:INDEX(A:A,ROWS(range))))>ROW(A1:INDEX(A:A,ROWS(range))),0,1),INDEX(sb,0,2)),
    idx,XMATCH(stock,rt,-1),
    IF(INDEX(rt,idx)=stock,INDEX(INDEX(sb,0,1),idx+1),
       INDEX(INDEX(sb,0,1),idx)))
    

    for the date and

    =LET(stock,300,range,C2:D9,sb,SORTBY(range,ROW(range),-1),
    rt,MMULT(IF(TRANSPOSE(ROW(A1:INDEX(A:A,ROWS(range))))>ROW(A1:INDEX(A:A,ROWS(range))),0,1),INDEX(sb,0,2)),
    idx,XMATCH(stock,rt,-1),
    IF(INDEX(rt,idx)=stock,INDEX(INDEX(sb,0,2),idx+1),
       stock-INDEX(rt,idx)))
    

    for the remaining volume.