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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
kjel
Frequent Visitor

Calculating Cumulative sum for last year

I'm using the following measure to get the cumulative totals for the periods a user has selected:
 
Sales CumSum =
CALCULATE(
    [Sales Amount],
    FILTER(ALLSELECTED('Date'),
    'Date'[DateTime] <= MAX('Date'[DateTime])
))
 
So if a user selects August, September and October 2022, they get a running total starting at 0. I would like to be able to create a measure to calculate last year's numbers as well, so that if a user selects the period August-October 2022, they get the cumulative 2021 total for these months.
1 ACCEPTED SOLUTION
daXtreme
Solution Sage
Solution Sage

Well, you have to shift the dates one year back. So, something like:

CALCULATETABLE(
    // This will move the entire
    // selected period one year back.
    DATEADD(
        'Date'[DateTime],
        -1,
        YEAR
    ),
    VAR MaxDate =
        MAX( 'Date'[DateTime] )
    VAR CurrentSelection =
        FILTER(
            ALLSELECTED( 'Date' ),
            'Date'[DateTime] <= MaxDate
        )
    RETURN
        CurrentSelection
)

Put this as the filter under your CALCULATE instead of your FILTER. This will be the running total for the same months but 1 year back. If you want to get the sum for all the selected months, then change your FILTER to be:

CALCULATETABLE(
    // This will move the entire
    // selected period one year back.
    DATEADD(
        'Date'[DateTime],
        -1,
        YEAR
    ),
    ALLSELECTED( 'Date' )
)

 

View solution in original post

3 REPLIES 3
daXtreme
Solution Sage
Solution Sage

Well, you have to shift the dates one year back. So, something like:

CALCULATETABLE(
    // This will move the entire
    // selected period one year back.
    DATEADD(
        'Date'[DateTime],
        -1,
        YEAR
    ),
    VAR MaxDate =
        MAX( 'Date'[DateTime] )
    VAR CurrentSelection =
        FILTER(
            ALLSELECTED( 'Date' ),
            'Date'[DateTime] <= MaxDate
        )
    RETURN
        CurrentSelection
)

Put this as the filter under your CALCULATE instead of your FILTER. This will be the running total for the same months but 1 year back. If you want to get the sum for all the selected months, then change your FILTER to be:

CALCULATETABLE(
    // This will move the entire
    // selected period one year back.
    DATEADD(
        'Date'[DateTime],
        -1,
        YEAR
    ),
    ALLSELECTED( 'Date' )
)

 

can you please explain it as i am unable to understand and i have asked the same question. will really be helpful if you could.

I have asked the same question in my this question

https://community.powerbi.com/t5/Service/How-to-cumulative-sum-for-previous-month-amp-previous-year-...

kjel
Frequent Visitor

That worked perfectly, thanks a lot!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.