cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate I
Advocate I

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

Accepted Solutions
Highlighted
Advocate I
Advocate I

Re: Cumulative total for last month

@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
Highlighted
Super User III
Super User III

Re: Cumulative total for last month

@Japsu

 

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 ) )
)

 

Try my new Power BI game Cross the River
Highlighted
Advocate I
Advocate I

Re: Cumulative total for last month

@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

Highlighted
Super User III
Super User III

Re: Cumulative total for last month

HI @Japsu

 

Could you share your file?

Try my new Power BI game Cross the River
Highlighted
Advocate I
Advocate I

Re: Cumulative total for last month

Highlighted
Super User III
Super User III

Re: Cumulative total for last month

Hi @Japsu

 

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] )
    )
)
Try my new Power BI game Cross the River
Highlighted
Advocate I
Advocate I

Re: Cumulative total for last month

@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.

Highlighted
Advocate I
Advocate I

Re: Cumulative total for last month

@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

Highlighted
Super User III
Super User III

Re: Cumulative total for last month

@Japsu

 

In 20 seconds I was about to write this

 

Smiley Very Happy

 

 

Try my new Power BI game Cross the River
Highlighted
Super User III
Super User III

Re: Cumulative total for last month

@Japsu

 

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

 

Try my new Power BI game Cross the River

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors