Forum Discussion

akim_no's avatar
akim_no
Icon for Helper III rankHelper III
9 months ago
Solved

12-month rolling cumulative

  I am trying to create a 12-month rolling cumulative of orders in Power BI with the following requirements: Each order has a start date and an order date. Between these two dates, the value o...
  • krishnakanth240's avatar
    krishnakanth240
    9 months ago

    Hi akim_no  Thank You

     

    Can you please check this measure

     

     

    Slicer Aware Cumulative =
    VAR CurrentDate =
    MAX ( 'Calendar'[Date] )

    VAR SlicerStart =
    MINX ( ALLSELECTED ( 'Calendar'[Date] ), 'Calendar'[Date] )

    RETURN
    SUMX (
    FILTER (
    Orders,
    -- Order must overlap slicer at least partially
    Orders[StartDate] <= CurrentDate
    && Orders[EndDate] >= SlicerStart
    ),
    VAR EffectiveStart =
    MAX ( Orders[StartDate], SlicerStart )

    VAR EffectiveEnd =
    MIN ( Orders[EndDate], CurrentDate )

    VAR ActiveDays =
    IF (
    EffectiveStart <= EffectiveEnd,
    1 + DATEDIFF ( EffectiveStart, EffectiveEnd, DAY ),
    0
    )

    VAR TotalDays =
    1 + DATEDIFF ( Orders[StartDate], Orders[EndDate], DAY )

    VAR DailyAmount =
    DIVIDE ( Orders[OrderAmount], TotalDays )

    RETURN
    DailyAmount * ActiveDays
    )

     

    Cumulative starts at slicer start
    Stops exactly at each order’s EndDate
    Works with overlapping orders
    Works for long slicer ranges (2026, 2027, etc.)
    No dependency on Calendar–Order relationship direction