Sum Last Three month

LearnMeExcel

Well-known Member
Joined
Aug 11, 2009
Messages
746
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi

I am trying to make this simple calculation
This is sample data
[TABLE="width: 134"]
<tbody>[TR]
[TD="width: 79"] Row Labels
[/TD]
[TD="width: 100"] Total Sales
[/TD]
[/TR]
[TR]
[TD="width: 79, bgcolor: transparent"] January
[/TD]
[TD="width: 100, bgcolor: transparent"] 645,142
[/TD]
[/TR]
[TR]
[TD="width: 79, bgcolor: transparent"] February
[/TD]
[TD="width: 100, bgcolor: transparent"] 938,921
[/TD]
[/TR]
[TR]
[TD="width: 79, bgcolor: transparent"] March
[/TD]
[TD="width: 100, bgcolor: transparent"] 546,220
[/TD]
[/TR]
[TR]
[TD="width: 79, bgcolor: transparent"] April
[/TD]
[TD="width: 100, bgcolor: transparent"] 865,123
[/TD]
[/TR]
[TR]
[TD="width: 79, bgcolor: transparent"] May
[/TD]
[TD="width: 100, bgcolor: transparent"] 1,010,323
[/TD]
[/TR]
[TR]
[TD="width: 79, bgcolor: transparent"] June
[/TD]
[TD="width: 100, bgcolor: transparent"] 702,331
[/TD]
[/TR]
[TR]
[TD="width: 79, bgcolor: transparent"] July
[/TD]
[TD="width: 100, bgcolor: transparent"] 1,014,847
[/TD]
[/TR]
[TR]
[TD="width: 79, bgcolor: transparent"] August
[/TD]
[TD="width: 100, bgcolor: transparent"] 1,596,815
[/TD]
[/TR]
[TR]
[TD="width: 79, bgcolor: transparent"] September
[/TD]
[TD="width: 100, bgcolor: transparent"] 1,474,167
[/TD]
[/TR]
[TR]
[TD="width: 79, bgcolor: transparent"] October
[/TD]
[TD="width: 100, bgcolor: transparent"] 1,604,745
[/TD]
[/TR]
[TR]
[TD="width: 79, bgcolor: transparent"] November
[/TD]
[TD="width: 100, bgcolor: transparent"] 2,383,518
[/TD]
[/TR]
[TR]
[TD="width: 79, bgcolor: transparent"] December
[/TD]
[TD="width: 100, bgcolor: transparent"] 3,424,852
[/TD]
[/TR]
[TR]
[TD="width: 79"] Grand Total
[/TD]
[TD="width: 100"] 16,207,005
[/TD]
[/TR]
</tbody>[/TABLE]

I want Measure to Calculate the Sum Of last four months
For example
In May
[SumOfLastFOurMonth]=2995406
And same for other month
This data for 2013 , that is mean for Feb [SumOfLastFOurMonth] = Oct2012+Nov2012+Dec2012+Jan2013
I hope my case is clear
Thank you


 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I am going to assume you have a Calender table, that has a MonthId, because that is fairly easy to achieve, and makes problem easier. The MonthId will not reset at each year. So, If Dec2012 is MonthId=12, then Jan2013 is MonthId=13.

=CALCULATE(SUM(FactTable[Sales]), FILTER(ALL(Calendar), Calendar[MonthId] < MAX(MonthId) && Calendar[MonthId] > MAX(MonthId) - 4)

Something like that... though, I'm not sure how well that will behave w/ Years or Days on rows, instead of Months...
 
Upvote 0
i will test it an tell you what is feed back
nay way thanks

i wll addolumn For month number in my data
 
Upvote 0
Scott
Doesn't work
in RowLabel i have month Name as above
in Year "Slicer Vertical" i select 2013
and in my Calendar i added New Column with name MonthId it is start from MonthId 1 TO 60 Month in My Calendar
and then i use this formula

Code:
=CALCULATE([Total Sales],
                        FILTER(ALL(Calendar),
                                                            Calendar[MonthId] < MAX(Calendar[MonLongN]) && 

                                                            Calendar[MonthId] > MIN(Calendar[MonLongN])))
it doesn't work
 
Upvote 0
Where do you have the data -- in a table that one can get with Insert | Table or a pivot table or in an ordinary range?
 
Upvote 0
I might need more info than "it doesn't work" so I can be helpful. But you also put a formula that isn't exactly close to what I said... missing the -4 ?
 
Upvote 0

Forum statistics

Threads
1,224,051
Messages
6,176,086
Members
452,704
Latest member
Michael AA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top