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
alvin_alpha
Frequent Visitor

Cumulative Sum, how to manage future periods

hey Folks,

I'm trying to get the cumulative sum - WTD per QTR and was able to get it using below formula:

 

<CSUM_QTY_IN = CALCULATE (SUM(Sheet1[VALUE]), FILTER(Sheet1, Sheet1[Index]<=EARLIER(Sheet1[Index])&&Sheet1[QTR]=EARLIER(Sheet1[QTR])))>

 

However, since its a cumulative sum per qtr, it seems to populate future weeks as below. Can y'all please help to advice how to deal with such scenarios? I just want my formula to populate till the current week but looks like it evaluating for the entire qtr.

 

Thanks,

 

data.JPG

1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @alvin_alpha 

You can use the below expresion, however you need to adjust it to your data model.

Sales Running Total = 
VAR mc = MAX('Calendar'[Date])
VAR mf = CALCULATE(MAX(Sales[OrderDateKey]), ALL(Sales)) >= mc
RETURN 
IF(
    mf,
    CALCULATE(
        [Sales],
        FILTER(
            ALL('Calendar'[Date]),
            'Calendar'[Date] <= mc
        )
    )
) 



Hope this helps
Mariusz

View solution in original post

2 REPLIES 2
alvin_alpha
Frequent Visitor

hi @Mariusz ,

thank you for the suggestion. I did miss to mention that my dates [QTR & WORKWEEK] are text fields due to a different WorkWeek definition we use. I did try out your formula but doesnt seem to work probably due to the date factor. let me play with it still.

thanks,

 

Mariusz
Community Champion
Community Champion

Hi @alvin_alpha 

You can use the below expresion, however you need to adjust it to your data model.

Sales Running Total = 
VAR mc = MAX('Calendar'[Date])
VAR mf = CALCULATE(MAX(Sales[OrderDateKey]), ALL(Sales)) >= mc
RETURN 
IF(
    mf,
    CALCULATE(
        [Sales],
        FILTER(
            ALL('Calendar'[Date]),
            'Calendar'[Date] <= mc
        )
    )
) 



Hope this helps
Mariusz

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.