Forum Discussion

RenierP's avatar
RenierP
Frequent Visitor
1 year ago
Solved

Aggregate across different timelines

Hi,   I have a system that records the qty in stock per material lot but only after a stock transaction. This means that a "slow-moving" SKU will only have a few qty recordings while a "fast-moving...
  • v-dineshya's avatar
    1 year ago

    Hi RenierP ,

    Thank you for reaching out to the Microsoft Community Forum.

    DAX measure 

    LastQty =
    VAR CurrentSKU = SELECTEDVALUE(Stock[SKU])
    VAR LastDate =
    CALCULATE(
    MAX(Stock[Date]),
    FILTER(
    ALL(Stock),
    Stock[SKU] = CurrentSKU &&
    Stock[Date] <= MAX(Calendar[Date])
    )
    )
    RETURN
    CALCULATE(
    MAX(Stock[QTY]),
    Stock[SKU] = CurrentSKU &&
    Stock[Date] = LastDate
    )
    Note:
    ALL(Stock) removes filters on the stock table to get a reliable max date. We re-apply the filter manually for the current SKU. It ensures we're always calculating the latest known stock per SKU, up to the current Calendar[Date].

     

    TotalStock Measure :

     

    TotalStock =
    SUMX(
    VALUES(Stock[SKU]),
    [LastQty]
    )
    Note : This will iterate over each SKU, get its last known quantity, and sum them.

     

    Use Calendar[Date] on the X-axis. Plot TotalStock. Add a slicer for SKU .

     

    If my response has resolved your query, please mark it as the Accepted Solution to assist others. Additionally, a 'Kudos' would be appreciated if you found my response helpful.

    Thank you