Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Mateusz_Płonka
Advocate I
Advocate I

Specific running total column - next n rows per level

Hi I need to include per row sum of column for next 12 indexs, but I have problem with my formula. 
Somebody know the solution? 
See me screen with description of result I need - probably need to fix conditionals but don't have idea how to do it.

Demand 13 Column =
CALCULATE(sum(DemandWeekly[DemandWeekly]),
                ALLEXCEPT(DemandWeekly,DemandWeekly[KeyDemandWeekly],DemandWeekly[ProductCode]),
                DemandWeekly[GroupIndex]>=EARLIER(DemandWeekly[GroupIndex]) && DemandWeekly[GroupIndex]<DemandWeekly[GroupIndex]+12  )



Mateusz_Ponka_0-1678909984958.png

 

1 ACCEPTED SOLUTION
MarkLaf
Solution Sage
Solution Sage

The relatively new WINDOW function is probably the best approach for this. 

Demand 13 Column = 
VAR _window = 
    WINDOW(
        0, 12,
        ORDERBY( DemandWeekly[GroupIndex], ASC ),
        PARTITIONBY( DemandWeekly[KeyDemandWeekly], DemandWeekly[ProductCode] ) 
    )
RETURN
CALCULATE( 
    SUM( DemandWeekly[DemandWeekly] ), 
    REMOVEFILTERS( DemandWeekly ),
    _window  
)

View solution in original post

1 REPLY 1
MarkLaf
Solution Sage
Solution Sage

The relatively new WINDOW function is probably the best approach for this. 

Demand 13 Column = 
VAR _window = 
    WINDOW(
        0, 12,
        ORDERBY( DemandWeekly[GroupIndex], ASC ),
        PARTITIONBY( DemandWeekly[KeyDemandWeekly], DemandWeekly[ProductCode] ) 
    )
RETURN
CALCULATE( 
    SUM( DemandWeekly[DemandWeekly] ), 
    REMOVEFILTERS( DemandWeekly ),
    _window  
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.