Forum Discussion

heiligbd's avatar
heiligbd
Icon for Helper I rankHelper I
3 years ago
Solved

Match Closest Length to Existing Available Length Between Two Tables

So I have two tables. One with new sales orders and one with existing inventory. I want to match the existing inventory to the sales orders by both material # and the closest length that is longer than the requested length. I can't match a sales order to shorter existing inventory but anything that is equal to or longer is acceptable.  Below would be sample examples of tables and what I would like to match in yellow between the batches and the lengths. In the example, you can see that some orders would not have matching inventory available, but others would potentially have multiple available lengths that would work, but I want the closest to (equal or longer) to match to the ordered length by best fit. Therefore, if you had an order at 3 length, and on hand inventory at 3.5 and 4, I would want 3.5 to match to the order not 4.

 

 

 

Table 1  
Sales Order #Material #Length Ordered
1A3
2A3.5
3B9
4C4
5B6.5
6A4.25
7C2

Thanks in advance for your help! 

Table 2  
Material #BatchOn Hand Length
A114.35
A222.95
A334.15
B448.5
B556.75
C664.25
C772.25

 

 

Matched Table    
Sales Order #MaterialLength OrderedMatched BatchOn Hand Length
1A3No MatchNo Match
2A3.5334.15
3B9No MatchNo Match
4C4664.25
5B6.5556.75
6A4.25114.35
7C2772.25
  • heiligbd,

     

    Try these calculated columns in Table1:

     

    Matched Batch = 
    VAR vMaterial = Table1[Material #]
    VAR vLengthOrdered = Table1[Length Ordered]
    VAR vInventory =
        FILTER (
            Table2,
            Table2[Material #] = vMaterial
                && Table2[On Hand Length] >= vLengthOrdered
        )
    VAR vMinOnHandLength =
        MINX ( vInventory, Table2[On Hand Length] )
    VAR vMinBatch =
        MINX (
            FILTER ( vInventory, Table2[On Hand Length] = vMinOnHandLength ),
            Table2[Batch]
        )
    VAR vResult =
        IF ( ISBLANK ( vMinBatch ), "No Match", CONVERT ( vMinBatch, STRING ) )
    RETURN
        vResult
    On Hand Length = 
    VAR vMaterial = Table1[Material #]
    VAR vLengthOrdered = Table1[Length Ordered]
    VAR vInventory =
        FILTER (
            Table2,
            Table2[Material #] = vMaterial
                && Table2[On Hand Length] >= vLengthOrdered
        )
    VAR vMinOnHandLength =
        MINX ( vInventory, Table2[On Hand Length] )
    VAR vResult =
        IF ( ISBLANK ( vMinOnHandLength ), "No Match", CONVERT ( vMinOnHandLength, STRING ) )
    RETURN
        vResult

     

     

2 Replies

  • heiligbd,

     

    Try these calculated columns in Table1:

     

    Matched Batch = 
    VAR vMaterial = Table1[Material #]
    VAR vLengthOrdered = Table1[Length Ordered]
    VAR vInventory =
        FILTER (
            Table2,
            Table2[Material #] = vMaterial
                && Table2[On Hand Length] >= vLengthOrdered
        )
    VAR vMinOnHandLength =
        MINX ( vInventory, Table2[On Hand Length] )
    VAR vMinBatch =
        MINX (
            FILTER ( vInventory, Table2[On Hand Length] = vMinOnHandLength ),
            Table2[Batch]
        )
    VAR vResult =
        IF ( ISBLANK ( vMinBatch ), "No Match", CONVERT ( vMinBatch, STRING ) )
    RETURN
        vResult
    On Hand Length = 
    VAR vMaterial = Table1[Material #]
    VAR vLengthOrdered = Table1[Length Ordered]
    VAR vInventory =
        FILTER (
            Table2,
            Table2[Material #] = vMaterial
                && Table2[On Hand Length] >= vLengthOrdered
        )
    VAR vMinOnHandLength =
        MINX ( vInventory, Table2[On Hand Length] )
    VAR vResult =
        IF ( ISBLANK ( vMinOnHandLength ), "No Match", CONVERT ( vMinOnHandLength, STRING ) )
    RETURN
        vResult

     

     

  • Awesome! Worked like a Champ! Thanks so much!