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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
dmalviya
Frequent Visitor

Issue with 12 month moving average formula - Need Help

Hi,

 

i am facing strange issue on calculating 12 month moving average. it is not summing values for last 12 month, instead only for current month & dividing by 12. However it is calculating 12 month correctly. I tried 3 different version but none of them are working.

 

Version 1 -

 

12 Month Sales Moving Average =
CALCULATE (
    SUM(Sales[Amount]),
    DATESBETWEEN (
        CalendarDate[Date],
        NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( CalendarDate[Date].[Date] ) ) ),
        LASTDATE ( CalendarDate[Date].[Date] )
    )
)
    / [Number of periods]

 

---------------------------------------------------------------

 

Version 2

 

12 Month Sales Moving Average =
CALCULATE(CALCULATE (
    SUMx(Sales,Sales[Amount]),FILTER(CalendarDate, CalendarDate[Date].[Date] >= NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( CalendarDate[Date].[Date] ) ) )
    && CalendarDate[Date].[Date] <= LASTDATE ( CalendarDate[Date].[Date] )
    )
)
    / [Number of periods])

 

--------------------------------------------------

 

Version 3

12 Month Sales Moving Average =
CALCULATE ( SUMX(Sales,Sales[Amount]),     
    DATESBETWEEN (
        CalendarDate[Date],
        NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( CalendarDate[Date] ) ) ),
        LASTDATE ( CalendarDate[Date])
    )
) / [Number of periods]

 

Please find attached sample file here -

 

https://1drv.ms/u/s!AgZ1uNPRA6n_g3ko7nmSnr0KNkU9

 

Thanks

Deepak

1 ACCEPTED SOLUTION
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @dmalviya,

Based on my test, you could refer to below steps:

I have created a date table and create relationship:

 

Date = CALENDARAUTO()

1.PNG

Create the measure:

 

MAT Sales = 
CALCULATE (
	SUM('Sales'[Amount]),
	DATESINPERIOD (
		'Date'[Date],
		LASTDATE ( 'Date'[Date] ),
		-1,
		YEAR
	)
)

Result:

1.PNG

 

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @dmalviya,

Based on my test, you could refer to below steps:

I have created a date table and create relationship:

 

Date = CALENDARAUTO()

1.PNG

Create the measure:

 

MAT Sales = 
CALCULATE (
	SUM('Sales'[Amount]),
	DATESINPERIOD (
		'Date'[Date],
		LASTDATE ( 'Date'[Date] ),
		-1,
		YEAR
	)
)

Result:

1.PNG

 

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.