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.
Hello,
How do I calculate a rolling average of a measure? Or is this not possible. I've tried everything I can find online. The measure is a conditional weighted average.
Solved! Go to Solution.
Hi,
Does this measure work?
=CALCULATE([FICO (Avg)],DATESBETWEEN(Calendar_Dates[Date],EDATE(MIN(Calendar_Dates[Date]),-5),MAX(Calendar_Dates[Date])),userelationship(Facts_Originations[PortStats.BookedDate], Calendar_Dates[Date]))
Ensure that in your visual Year and Month are dragged from the Calendar_Dates table.
Can you share a pbix along with the example output
Hi,
Does this measure work?
=CALCULATE([FICO (Avg)],DATESBETWEEN(Calendar_Dates[Date],EDATE(MIN(Calendar_Dates[Date]),-5),MAX(Calendar_Dates[Date])),userelationship(Facts_Originations[PortStats.BookedDate], Calendar_Dates[Date]))
Ensure that in your visual Year and Month are dragged from the Calendar_Dates table.
Hello @Ashish_Mathur
Thank you for the reply. I was on my home computer attempting your solution and for whatever reason, it did not behave the same as it is behaving on my work computer.
I've never used EDATE before, so I had to read about the formula this morning. When I modify your formula to use EOMONTH instead, then it works. The problem with EDATE is that it does not go to the last day of the month but rather that month prior. For example, EDATE (2/28/2019, -5) is 9/28/2018. The same with EDATE (11/30/2019, -1) would give 10/30/2019, not 10/31/2019.
Since my rolling average is full calendar months, I switched it to EOMONTH and now it works.
You are welcome. Thank you for correcting my mistake.
Thanks for the help @Ashish_Mathur , but that measure just calculates the same number and puts it in every time period (even time periods before when the data starts). It also takes a long time to complete the calculation when added to the table
Hi,
Let's start from scratch. Explain the business question, share some data and show the expected result.
Hey @rawiswarden ,
I would give this pattern a try
Rolling Fico AVG =
var _thecurrentMonth = MAX(Calendar_Dates[Date])
var _theLastSixMonths = ...
return
AVERAGEX(
_theLastSixMonths
, [FICO (Avg)]
)
It depends how easily it is to determine the last six months from your calendar table.
Regards,
Tom
Hello @TomMartens ,
My calendar table is below. Is there anything I should add or how would I determine the month end? I can't figure out how to define the second variable. I've tried using eomonth and a combination of the DAX date functions.
Hey @rawiswarden
As far as I understand you need the average of 6 months, as far as I see you iterate across the table FACT_Originations, this was not was I meant.
First I added a new calcualted column to the calendar table like so (please be aware, that it is references my fact table):
"Running Month Index" ,
var YearStart = YEAR(MIN('Fact Sale'[Invoice Date Key]))
return
((YEAR([Date]) - YearStart) * 12 ) + MONTH([Date])
This creates an index for each month. This allows to navigate between months using simple integer maths.
The measure below concatenates the last six months, just for checking if the "correct"months are selected.
test =
var maxRunningMonthIndex = CALCULATE(MAX('Calendar_Dates'[Running Month Index]))
var t =
SUMMARIZE(
FILTER(
'Calendar_Dates'
, 'Calendar_Dates'[Running Month Index] >= maxRunningMonthIndex - 5 && 'Calendar_Dates'[Running Month Index] <= maxRunningMonthIndex
)
, 'Calendar_Dates'[Running Month Index]
)
return
CONCATENATEX(
t
, [Running Month Index]
, " | "
)
This allows to created something like this:
Of course your measure would look like this:
Rolling FICO (Avg) =
var maxRunningMonthIndex = CALCULATE(MAX('Calendar_Dates'[Running Month Index]))
var t =
SUMMARIZE(
FILTER(
'Calendar_Dates'
, 'Calendar_Dates'[Running Month Index] >= maxRunningMonthIndex - 5 && 'Calendar_Dates'[Running Month Index] <= maxRunningMonthIndex
)
, 'Calendar_Dates'[Running Month Index]
)
return
AVERAGEX(
t
, [FICO (Avg)]
)
Hopefully this is what you are looking for.
Regards,
Tom
Hello @TomMartens
Thanks for the help but I must be terrible at DAX. I am going getting the correct data in the total
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
97 | |
85 | |
70 | |
61 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |