Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Return Latest Price for Multiple Lines

Hello all!  First off, thanks in advance for any help anyone can provide, it is greatly appreciated!   I have done a lot of searching, and can't quite find anything that I can get to work.  As some...
  • v-alq-msft's avatar
    6 years ago

    Hi, Anonymous 

     

    Based on your description, I created data to reproduce your scenario.

    InventorySitesOn-Hand:

     

    InventItemPrices:

     

    There is many-to-one relationship between 'InventItemPrices' and 'InventorySitesOn-Hand' tables.

     

    You may create a calculated column in InventorySitesOn-Hand as below.

     

    Result = 
    var _itemnum = 'InventorySitesOn-Hand'[ItemNumber]
    var _latestdatetime = 
    CALCULATE(
        MAX(InventItemPrices[PriceCreatedDateTime]),
        FILTER(
            ALL(InventItemPrices),
            InventItemPrices[ItemNumber] = _itemnum
        )
    )
    var _price = 
    CALCULATE(
        SUM(InventItemPrices[Price]),
        FILTER(
            ALL(InventItemPrices),
            InventItemPrices[PriceCreatedDateTime] = _latestdatetime&&
            InventItemPrices[ItemNumber] = _itemnum
        )
    )
    return
    [OnHandQuantity]*_price

     

     

    Result:

     

    Best Regards

    Allan

     

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