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
Chinoos
Helper I
Helper I

Rolling 12 month sum for completed months

I'm struggling to get rolling 12 months for the months are completed. For example; For the current month the value should display Zero and for the completed month it should display rolling 12 months values. For 2016-Dec the value=sum(2016-Jan till 2016-Dec), 2016-Nov=sum(2015-Dec till 2016-Nov)

 

YearMonthValue
20168985193929.9
20169985428542.2
201610985365989.1
201611992519096.7
201612980109375.8
201710

 

Please suggest any idea, if you have come across the same

4 ACCEPTED SOLUTIONS
Vvelarde
Community Champion
Community Champion

@Chinoos

 

you can check if a month is complete with: (Bold Part)

 

ValueCalc = if(TODAY()>=EOMONTH(VALUES(Table1[DateRef]);0);EXPRTRUE;EXPRFALSE)




Lima - Peru

View solution in original post

v-shex-msft
Community Support
Community Support

Hi @Chinoos,

 

According to your description, you can refer to below formulas if it works on your side.

 

1. Calculate the total value from previous date to current date.

 

Total = 
var minDate= DATE(YEAR(MAX([Date])),MONTH(MAX([Date]))-11,DAY(MAX([Date])))
return 
SUMX(FILTER(ALL('Table'),[Date]>= minDate&&[Date]<=MAX([Date])),[Amount])

 

2. Calculate the rolling total in current year.

 

Rolling total = SUMX(FILTER(ALL('Table'),[Date]<=MAX([Date])&&[Date].[Year]=MAX([Date].[Year])),[Total])

 

 

If above is not help, please share some sample data to test.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

Thanks the formulas, it worked for rolling 12 months sum, but i had mades some changes since date and measure are coming from 2 different tables. I'm using just one formula to get the result.

 

Rolling 12 months =
var minDate= DATE(YEAR(MAX('Fiscal Calendar Date'[Fiscal Calendar Date])),MONTH(MAX('Fiscal Calendar Date'[Fiscal Calendar Date]))-12,DAY(MAX('Fiscal Calendar Date'[Fiscal Calendar Date])))
return
CALCULATE( SUM ( 'Sales'[Gross Sales] ),FILTER(ALL('Fiscal Calendar Date'),'Fiscal Calendar Date'[Fiscal Calendar Date]> minDate&&'Fiscal Calendar Date'[Fiscal Calendar Date]<=MAX('Fiscal Calendar Date'[Fiscal Calendar Date])))

 

Please find the sample date below( from the Fiscal Calendar Date Hierarchy, I'm dsiplaying only the Year and Month)

YearMonthGross
2015January55039455.96
2015February49964844.34
2015March67875264.74
2015April85248808.27
2015May88028313.78
2015June97662930.16
2015July93672919.35
2015August89597379.02
2015September93686553.51
2015October97872548.47
2015November81438568.72
2015December77867879.91
2016January55328963.33
2016February61547754.60
2016March78241869.13
2016April81956103.71
2016May89760083.71
2016June96347579.89
2016July83884792.87
2016August97057881.05
2016September95230929.74
2016October90063862.46
2016November90997731.83
2016December59691823.46

View solution in original post

As mentioned earlier, this is actually better suited for DAX, assuming that you've got a full data model in place (eg, a date table). Power Query (ie 'M') has performance issues - for example, if your dataset has a lot of columns in it, then it will run much slower than one that has just a few columns). So you might treat this as an exercise in getting familiar with what is possible in M, even if it's not the best approach.

 

In DAX, you might try something like this - 
using the recommended idea of having building blocks of measures, create a measure for total net sales:
TotalNetSales = SUM( [NETSALES] )

Then a measure for rolling 12month sales:
12MonthRollingSales =
CALCULATE([TotalNetSales],
DATESINPERIOD(DimDates[Date],
LASTDATE(DimDates[Date]),-12, Month
)
)

... that's of course assuming that the fact table is connected to a proper date table (DimDates in my example, where [Date] is every calendar date - provided that MONTH_FISCAL is a proper date, then it can be linked to the date table)

View solution in original post

17 REPLIES 17

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.