Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hi,
I need to use DAX to calculate the LTM value in 2 steps as illustrated below in the excel.
Step-1: the monthly value is calculate by an average value of last two months.
AC15 = (AB12 + AC12) / 2
AB15 = (AA12 + AB12) / 2
...
Step-2: passing these average values as an input of each month into a sum of rolling 12 months. And then make an average value of the result from the sum of rolling 12 months.
AC18 = average(R15:AC15)
The actual table is not like this excel. There are one column [Date] and another column [ActivePortfolio].
I use this DAX formula for step-1. This gives me correct result.
[MonthlyValue] := CALCULATE (SUM([ActivePortfolio]), DATESINPERIOD (row5, LASTDATE( [Date] ), -2, MONTH)) / 2
But if I use the following DAX formula in step-2, it returns a very small value for that month (AC18).
[LTMValue] := CALCULATE ([MonthlyValue], DATESINPERIOD (row5, LASTDATE( [Date] ), -12, MONTH)) / 12
So what's wrong in the DAX [LTMValue]?
Solved! Go to Solution.
If [MonthlyValue] is calculated correctly, then [LTMValue] is THE AVERAGE of [MonthlyValue] over the period of 12 months, not just CALCULATE( [MonthlyValue], ...). You have to do two things:
By the way, you have to have a 'Date' table that joins to your Portfolios and which is marked as DATE TABLE in the model and covers full years of the dates found in Portfolios[Date].
var __lastVisibleDate = LASTDATE( 'Date'[Date] )
var __startDate = PREVIOUSYEAR( __lastVisibleDate ) + 1
var __months =
CALCULATETABLE(
VALUES( 'Date'[Month] ), -- Month must be unique across years
DATESBETWEEN(
'Date'[Date],
__startDate,
__lastVisibleDate
)
)
var __average =
CALCULATE(
AVERAGEX(
__months,
[MonthlyValue]
),
ALL( 'Date' )
)
return
__average
If the last visible date in your selections is the last date of a month, this will work correctly
If [MonthlyValue] is calculated correctly, then [LTMValue] is THE AVERAGE of [MonthlyValue] over the period of 12 months, not just CALCULATE( [MonthlyValue], ...). You have to do two things:
By the way, you have to have a 'Date' table that joins to your Portfolios and which is marked as DATE TABLE in the model and covers full years of the dates found in Portfolios[Date].
var __lastVisibleDate = LASTDATE( 'Date'[Date] )
var __startDate = PREVIOUSYEAR( __lastVisibleDate ) + 1
var __months =
CALCULATETABLE(
VALUES( 'Date'[Month] ), -- Month must be unique across years
DATESBETWEEN(
'Date'[Date],
__startDate,
__lastVisibleDate
)
)
var __average =
CALCULATE(
AVERAGEX(
__months,
[MonthlyValue]
),
ALL( 'Date' )
)
return
__average
If the last visible date in your selections is the last date of a month, this will work correctly