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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Cumulative total for last month

Hey

I have a measure for cumulative total that sums up values from a certain date forward. This works as intended.

 

cumulative total = CALCULATE([Total]; DATESBETWEEN(Calendar[Date]; MIN('Dimension'[StartDate]); MAX(Calendar[Date])))

 

 

Now I need an another measure that shows cumulative total up until last month. Here's what I have, it seems to be close to what I look for.

cumulative total (lm) = CALCULATE([cumulative total]; DATEADD(Calendar[Date]; -1; Month))

But not quite.
cumulative total.JPG

Cumulative total (lm) measure works except for the very first month. That 15600 you see at January 2017 is the cumulative total for 2017 and 2018, but it should be 0 or null, since January 2017 is the first month and there is no last month available.

 

I appreciate all the help.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Zubair_Muhammad

 

So, I toyed around with your suggestion a bit. I think I got it.

Cumulative total = 
CALCULATE (
    [Total];
    FILTER (
        ALL ('Calendar');
        'Calendar'[Date] >= MIN('Dimension'[StartDate]) &&
        'Calendar'[Date] <= MAX('Calendar'[Date])))

This way cumulative total (lm) seems to be working and column totals aswell. I'll still have to double and triple check everything against the actual model and data. But at first glance looks alright.

 

screenshot.JPG

Thank you for steering me the right direction. You were a great help.

 

View solution in original post

9 REPLIES 9
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous

 

Try this..... But if you need Dec 2017 balance in Jan 2018 this would fail.

 

cumulative total (lm) =
IF (
    MONTH ( SELECTEDVALUE ( Calendar[Date] ) ) > 1,
    CALCULATE ( [cumulative total], DATEADD ( Calendar[Date], -1, MONTH ) )
)

 

Anonymous
Not applicable

@Zubair_Muhammad

 

I tried your suggestion, but every month ends up being blank. And yes I would need cumulative totals to cover multiple years. 

 

I changed the data little bit to better illustrate the scenario. We have dimension (a project or a service or whatever) that starts on April 2017 and ends October 2018. We have a measure (cumulative total) that calculates cumulative totals from start to end without resetting (not a ytd measure) and another measure (cumulative total lm) that basically does the same but stays one month behind.

 

My original measures do that, with the exception of the very begin. Somehow January 2017 gets a value of 10600 which is the final value from November 2018.


screenshot.JPG

HI @Anonymous

 

Could you share your file?

Anonymous
Not applicable

Hi @Anonymous

 

If you revise the Cumulative Total formula as per below, you will get the correct Cumulative Total (lm) as well.

 

cumulative total =
CALCULATE (
    [Total],
    FILTER (
        ALL ( Calendar[Date] ),
        'Calendar'[Date] <= MIN ( 'Calendar'[Date] )
            && 'Calendar'[Date] >= MIN ( 'Dimension'[StartDate] )
    )
)
Anonymous
Not applicable

@Zubair_Muhammad

 

So, I toyed around with your suggestion a bit. I think I got it.

Cumulative total = 
CALCULATE (
    [Total];
    FILTER (
        ALL ('Calendar');
        'Calendar'[Date] >= MIN('Dimension'[StartDate]) &&
        'Calendar'[Date] <= MAX('Calendar'[Date])))

This way cumulative total (lm) seems to be working and column totals aswell. I'll still have to double and triple check everything against the actual model and data. But at first glance looks alright.

 

screenshot.JPG

Thank you for steering me the right direction. You were a great help.

 

@Anonymous

 

In 20 seconds I was about to write this

 

Smiley Very Happy

 

 

@Anonymous

 

But I still donot know why your formula doesn't work for first month

 

Anonymous
Not applicable

@Zubair_Muhammad

 

I really appreciate your efforts, but unfortunately your suggestion messed up the totals. So it's a no go.

screenshot.png

Actually the missing 2017 column totals don't matter, but the very end has to match, 10600 in this case.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.