Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Help for supply chain minimum quantity requirement

Hello!   I have some difficulties to create the good formula..   My case is this one :   I have some materials which need to have always at a special storage location a minimum of stock quantit...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi  Anonymous ,

     

    Maybe you can try formula like below to create measure:

    Deficit = 
    VAR CurrentStock =
        CALCULATE (
            SUM ( 'Stock'[Quantity] ),
            'Stock'[Storage Location] = "A01"
        )
    VAR MinimumStock =
        LOOKUPVALUE (
            'Mini'[Minimum Quantity],
            'Mini'[Item], MAX ( 'Stock'[Item] )
        )
    RETURN
        MAX ( 0, MinimumStock - CurrentStock )
    
    Batches = 
    VAR RequiredStock = [Deficit]
    VAR BatchTable =
        FILTER (
            'Stock',
            'Stock'[Storage Location] = "A02"
                && 'Stock'[Item] = MAX(  'Stock'[Item] )
        )
    VAR SortedBatchTable =
        ADDCOLUMNS (
            BatchTable,
            "CumulativeStock",
                SUMX (
                    FILTER ( BatchTable, [Creation Date] <= EARLIER ([Creation Date] ) ),
                    [Quantity]
                )
        )
    VAR SelectedBatches =
        CONCATENATEX (
            FILTER ( SortedBatchTable, [CumulativeStock] <= RequiredStock ),
            [Batch],
            "/",
            [Creation Date], ASC
        )
    RETURN
        SelectedBatches
    

     

    Best Regards,
    Adamk Kong

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.