This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
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
Solved! Go to Solution.
Hi @dmalviya,
Based on my test, you could refer to below steps:
I have created a date table and create relationship:
Date = CALENDARAUTO()
Create the measure:
MAT Sales =
CALCULATE (
SUM('Sales'[Amount]),
DATESINPERIOD (
'Date'[Date],
LASTDATE ( 'Date'[Date] ),
-1,
YEAR
)
)
Result:
You could also download the pbix file to have a view.
Regards,
Daniel He
Hi @dmalviya,
Based on my test, you could refer to below steps:
I have created a date table and create relationship:
Date = CALENDARAUTO()
Create the measure:
MAT Sales =
CALCULATE (
SUM('Sales'[Amount]),
DATESINPERIOD (
'Date'[Date],
LASTDATE ( 'Date'[Date] ),
-1,
YEAR
)
)
Result:
You could also download the pbix file to have a view.
Regards,
Daniel He
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 31 | |
| 23 | |
| 22 | |
| 20 | |
| 15 |
| User | Count |
|---|---|
| 64 | |
| 41 | |
| 27 | |
| 22 | |
| 20 |