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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Thamizh_hfhs
Helper I
Helper I

Last 6 months rolling average DAX measure

Hi Everyone. I have a measure which calculates the last 6 months rolling average of CMAED as follows,

 

Last 6 Months CMAED Average = DIVIDE(CALCULATE('FactGeneralLedger'[CMAEDCDSMonthlytotal], DATESINPERIOD('DimDate'[DateValue], MAX(DimDate[DateValue]), -6, MONTH)), 6)   

I have a "MonthYear" filter and whenever I select a MonthYear, for example September2022, the above measure calculates the average from April to September. But, I wanted the average from March to August. How do I alter the above measure  to get the desired result? Thanks in advance.


Please see sample below. For the September month,

The current measure gives the last 6 months average as 2,375 (April to September)
But I need the average to be 2,125 (March to August)
How do I alter my measure to get the desired result ?

Month YearCMAED
01-20221,000
02-20221,250
03-20221,500
04-20221,750
05-20222,000
06-20222,250
07-20222,500
08-20222,750
09-20223,000
1 ACCEPTED SOLUTION

Hi @Thamizh_hfhs ,

Please try:

 

Measure 2 = 
VAR _YEAR = MAX('DimDate'[Year])
VAR _MONTH = MAX('DimDate'[Month])
VAR _PRE_MONTH = IF(_MONTH=1,12,_MONTH-1)
VAR _PRE_YEAR = IF(_MONTH=1,_YEAR-1,_YEAR)
VAR _DATE = CALCULATE(MAX('DimDate'[DateValue]),FILTER(ALL('DimDate'),'DimDate'[Year]=_PRE_YEAR&&'DimDate'[Month]=_PRE_MONTH))
VAR _RESULT = DIVIDE(CALCULATE(SUM('FactGeneralLedger'[CMAEDCDSMonthlytotal]),DATESINPERIOD('DimDate'[DateValue],_DATE,-6, MONTH)),6)
RETURN
_RESULT

 

vcgaomsft_0-1668672762770.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Thamizh_hfhs , Try a  measure like

 

6 Month Avg = CALCULATE(AverageX(Values('Date'[MONTH Year]),calculate(Sum('Table'[CMAED])))
,DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-6,MONTH))

Last 6 months CMAED Test = CALCULATE(AVERAGEX(VALUES('DimDate'[MonthYear]), CALCULATE('FactGeneralLedger'[CMAEDCDSMonthlyTotal])), DATESINPERIOD('DimDate'[DateValue], MAX('DimDate'[DateValue]), -6, MONTH))
 
I tried and it gives the same result i.e; 2,375 (April to September). Doesn't seem to be working unfortunately.

Hi @Thamizh_hfhs ,

Please try:

 

Measure 2 = 
VAR _YEAR = MAX('DimDate'[Year])
VAR _MONTH = MAX('DimDate'[Month])
VAR _PRE_MONTH = IF(_MONTH=1,12,_MONTH-1)
VAR _PRE_YEAR = IF(_MONTH=1,_YEAR-1,_YEAR)
VAR _DATE = CALCULATE(MAX('DimDate'[DateValue]),FILTER(ALL('DimDate'),'DimDate'[Year]=_PRE_YEAR&&'DimDate'[Month]=_PRE_MONTH))
VAR _RESULT = DIVIDE(CALCULATE(SUM('FactGeneralLedger'[CMAEDCDSMonthlytotal]),DATESINPERIOD('DimDate'[DateValue],_DATE,-6, MONTH)),6)
RETURN
_RESULT

 

vcgaomsft_0-1668672762770.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.