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

Average last six months not including the current month

I have a table of data that shows the values for each attribute at the end of each month. like below:

elimey_0-1642072184937.png

The data model is pretty simple. I have created an Autocalender with a MonthEnd column and the data model look like this:

elimey_1-1642072246482.png

 

What I need is a measure that calculates the average of the past six months, not including the current month. 
For instance:

- for 12.2021, we need to calculate the average of 11.2021-06.2021

- for 11.2021, we need to calculate the average of 10.2021-05.2021

The ultimate goal is to compare the value for the current month with the average of the past 6 months.

I wrote this measure: 

AVG_LAST_SIX_MONTH =
CALCULATE( AVERAGE(DPD[Value]), DATESINPERIOD('Calendar'[Date], MAX('Calendar'[Date])-1, -6, MONTH))
But the result is not correct: 
elimey_2-1642072505568.png

can someone tell me where am I doing wrong?

 

1 ACCEPTED SOLUTION
elimey
Frequent Visitor

but this works perfectly:

AVG_LAST_SIX_MONTH =
CALCULATE (
SUM ( DPD[Value] ),
DATESINPERIOD (
'Calendar'[Date],
EOMONTH ( MAX ( 'Calendar'[Date] ), -1 ),
-6,
MONTH
)
) / 6

now I am confused. What does Average do?

View solution in original post

2 REPLIES 2
elimey
Frequent Visitor

but this works perfectly:

AVG_LAST_SIX_MONTH =
CALCULATE (
SUM ( DPD[Value] ),
DATESINPERIOD (
'Calendar'[Date],
EOMONTH ( MAX ( 'Calendar'[Date] ), -1 ),
-6,
MONTH
)
) / 6

now I am confused. What does Average do?
amitchandak
Super User
Super User

@elimey Try like, last 6 month before selected month

 

AVG_LAST_SIX_MONTH =
CALCULATE( AVERAGE(DPD[Value]), DATESINPERIOD('Calendar'[Date], eomonth(MAX('Calendar'[Date]),-1) , -6, MONTH))

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.