Forum Discussion

heiligbd's avatar
heiligbd
Helper 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 th...
  • DataInsights's avatar
    3 years ago

    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

     

     

  • heiligbd's avatar
    3 years ago

    Awesome! Worked like a Champ! Thanks so much!