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

I am trying to calculate a running total over previous 12 months, for each month of year

I am trying to calculate the previous 12 months running total for each month. Example: If I select year 2020 and month Dec in the slicer. The table should display from Jan 2020 to Dec 2020 and Dec 2020 running total should be the sum of Jan 2020 to Dec 2020. If I select the year 2020  and the Month Nov then the table should display data from Dec 2019 to Nov 2020 and Nov 2020 running total should be the sum of Dec 2019 to Nov 2020.

 

YearMonthValuesRunning Total of previous 12 months for each months 
201915  
201926  
201931  
201942  
201953  
201964  
201971  
201985  
201996  
2019101  
2019112  
2019123  
20201135Running total from Feb-2019 to Jan-2020
20202231Running total from Mar-2019 to Feb-2020
20203333Running total from Apr-2019 to Mar-2020
20204435Running total from May-2019 to Apr-2020
20205133Running total from Jun-2019 to May-2020
20206534Running total from Jul-2019 to Jun-2020
20207639Running total from Aug-2019 to Jul-2020
20208135Running total from Sep-2019 to Aug-2020
20209231Running total from Oct-2019 to Sep-2020
202010333Running total from Nov-2019 to Oct-2020
202011233Running total from Dec-2019 to Nov-2020
202012131Running total from Jan-2020 to Dec-2020

 

2 ACCEPTED SOLUTIONS

Hi, 

mine is also August 2021 version.

 

What I meant was, I could not access to your link.

 

Thank you.

 

 

Picture3.png

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

https://www.dropbox.com/s/xgf8cztetxl562t/Sample.pbix?dl=0 

 

 

Cumulate previous 12 months : =
VAR _slicerselect =
SELECTEDVALUE ( IndepnedentCalendartable[Year] ) * 12
+ SELECTEDVALUE ( IndepnedentCalendartable[Month] )
VAR _latestyear =
CALCULATE ( MAX ( 'Date'[Year] ), ALL () )
VAR _latestmonth =
CALCULATE ( MAX ( 'Date'[Month] ), ALL () )
VAR _yearmonthoffsetnumber_current =
SELECTEDVALUE ( 'Date'[Year], _latestyear ) * 12
+ SELECTEDVALUE ( 'Date'[Month], _latestmonth )
VAR _period_12_months =
FILTER (
ALL ( 'Date' ),
'Date'[Year] * 12 + 'Date'[Month] <= _yearmonthoffsetnumber_current
&& 'Date'[Year] * 12 + 'Date'[Month] > _yearmonthoffsetnumber_current - 12
)
RETURN
IF (
_yearmonthoffsetnumber_current <= _slicerselect
&& _yearmonthoffsetnumber_current >= _slicerselect - 11,
CALCULATE ( SUM ( 'Values'[Values] ), _period_12_months ),
BLANK ()
)

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

9 REPLIES 9
Jihwan_Kim
Super User
Super User

Picture4.png

 

Cumulate previous 12 months : =
VAR _latestyear =
CALCULATE ( MAX ( Data[Year] ), ALL () )
VAR _latestmonth =
CALCULATE ( MAX ( Data[Month] ), ALL () )
VAR _yearmonthoffsetnumber_current =
SELECTEDVALUE ( Data[Year], _latestyear ) * 12
+ SELECTEDVALUE ( Data[Month], _latestmonth )
VAR _period_12_months =
FILTER (
ALL ( Data ),
Data[Year] * 12 + Data[Month] <= _yearmonthoffsetnumber_current
&& Data[Year] * 12 + Data[Month] >= _yearmonthoffsetnumber_current - 11
)
RETURN
CALCULATE ( SUM ( Data[Values] ), _period_12_months )

 

 

 

Link to the sample pbix file 

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hi @Jihwan_Kim 

 

Thanks for sharing the file. I have tried the same measure on my power bi file. It's displaying unexpected results. Can you please create the measure in my sample file. I have attached here.

Onedrive 

Thanks

Hi,

I cannot open your shared file.

Could you please check?

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hi,

banupriya45_0-1629381418007.png

 

I am using the August 2021 version 

Hi, 

mine is also August 2021 version.

 

What I meant was, I could not access to your link.

 

Thank you.

 

 

Picture3.png

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Can you try with the Samplefile link please

https://www.dropbox.com/s/xgf8cztetxl562t/Sample.pbix?dl=0 

 

 

Cumulate previous 12 months : =
VAR _slicerselect =
SELECTEDVALUE ( IndepnedentCalendartable[Year] ) * 12
+ SELECTEDVALUE ( IndepnedentCalendartable[Month] )
VAR _latestyear =
CALCULATE ( MAX ( 'Date'[Year] ), ALL () )
VAR _latestmonth =
CALCULATE ( MAX ( 'Date'[Month] ), ALL () )
VAR _yearmonthoffsetnumber_current =
SELECTEDVALUE ( 'Date'[Year], _latestyear ) * 12
+ SELECTEDVALUE ( 'Date'[Month], _latestmonth )
VAR _period_12_months =
FILTER (
ALL ( 'Date' ),
'Date'[Year] * 12 + 'Date'[Month] <= _yearmonthoffsetnumber_current
&& 'Date'[Year] * 12 + 'Date'[Month] > _yearmonthoffsetnumber_current - 12
)
RETURN
IF (
_yearmonthoffsetnumber_current <= _slicerselect
&& _yearmonthoffsetnumber_current >= _slicerselect - 11,
CALCULATE ( SUM ( 'Values'[Values] ), _period_12_months ),
BLANK ()
)

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Thanks alot. It's working perfectly 🙂

 

Tanushree_Kapse
Impactful Individual
Impactful Individual

Hi @banupriya45 ,

 

I would suggest you to first create a dates column and then

Use this measure for Running Total:

 

Date= DATE(YEAR(Year), MONTH(Month), 1)
Running Total = CALCULATE(SUM(Values), DATESINPERIOD(Date, LASTDATE(Date), -12, MONTH))

 

Mark this as a solution if I answered your question, Kudos are always appreciated.

 

Thanks.

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.

Top Solution Authors