Forum Discussion

andresVISA's avatar
andresVISA
Regular Visitor
4 years ago
Solved

On hand Inventory Shipments (FIFO)

Hello, This is my first post so I want to thank in advance for any help received. What I'm trying to accomplish is to display the separate shipments that make up current inventory levels by product ...
  • v-jianboli-msft's avatar
    4 years ago

    Hi andresVISA ,

     

    Please try:

    Measure =
    VAR _a =
        ADDCOLUMNS (
            ALL ( 'Shipments' ),
            "sum",
                SUMX (
                    FILTER (
                        ALL ( 'Shipments' ),
                        [ItemCode] = EARLIER ( Shipments[ItemCode] )
                            && [Itemname] = EARLIER ( Shipments[Itemname] )
                            && VALUE (
                                RIGHT ( [Shipment date (Qtr)], 2 )
                                    & RIGHT ( LEFT ( [Shipment date (Qtr)], 2 ), 1 )
                            )
                                >= VALUE (
                                    RIGHT ( EARLIER ( [Shipment date (Qtr)] ), 2 )
                                        & RIGHT ( LEFT ( EARLIER ( [Shipment date (Qtr)] ), 2 ), 1 )
                                )
                    ),
                    [Qty]
                )
        )
    VAR _b =
        MAXX (
            FILTER ( _a, [Shipment date (Qtr)] = MAX ( 'Shipments'[Shipment date (Qtr)] ) ),
            [sum]
        )
    VAR _c =
        MAXX (
            FILTER (
                'Inventory',
                [ItemCode] = MAX ( 'Shipments'[ItemCode] )
                    && [Itemname] = MAX ( 'Shipments'[Itemname] )
            ),
            [ On hand ]
        )
    VAR _d =
        MINX (
            FILTER (
                _a,
                VALUE (
                    RIGHT ( [Shipment date (Qtr)], 2 )
                        & RIGHT ( LEFT ( [Shipment date (Qtr)], 2 ), 1 )
                )
                    = MINX (
                        FILTER (
                            _a,
                            [ItemCode] = MAX ( 'Shipments'[ItemCode] )
                                && [Itemname] = MAX ( 'Shipments'[Itemname] )
                                && [sum] <= _c
                        ),
                        VALUE (
                            RIGHT ( [Shipment date (Qtr)], 2 )
                                & RIGHT ( LEFT ( [Shipment date (Qtr)], 2 ), 1 )
                        )
                    )
            ),
            [Shipment date (Qtr)]
        )
    RETURN
        SWITCH (
            TRUE (),
            _c >= _b
                && MAX ( 'Shipments'[Shipment date (Qtr)] ) <> _d, MAX ( 'Shipments'[Qty] ),
            _c >= _b
                && MAX ( 'Shipments'[Shipment date (Qtr)] ) = _d,
                MAX ( 'Shipments'[Qty] ) + _c - _b,
            BLANK ()
        )
    

    Final output:

    Best Regards,

    Jianbo Li

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