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.
Hi everybody! I have a problem calculating a moving average in power bi ( getting wrong results ) and I can't find my mistake.
My moving average for 3 days is calculated this way:
So I expected that the moving average displayed in the line in each day should be the average of 3 previous days, but it is a value much bigger than that. Could someone help me to understand what am I doing wrong ?
The .pbix with the example:
Thanks in advance,
Regards
Solved! Go to Solution.
Hi, @gustavo80
Thank you for providing sample data. You may create a measure as below. The pbix file is attached in the end.
Moving_Average_3_Days 2 =
var tab =
SUMMARIZE(
'Dataset',
'Dataset'[install_date],
"avg",
var _installdate = [install_date]
return
AVERAGEX(
FILTER(
SUMMARIZE(
ALL('Dataset'),
'Dataset'[install_date],
"Day1%",
[Day1 %]
),
[install_date]<=_installdate&&[install_date]>=_installdate-2
),
[Day1%]
)
)
return
SUMX(
tab,
[avg]
)
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @gustavo80
Thank you for providing sample data. You may create a measure as below. The pbix file is attached in the end.
Moving_Average_3_Days 2 =
var tab =
SUMMARIZE(
'Dataset',
'Dataset'[install_date],
"avg",
var _installdate = [install_date]
return
AVERAGEX(
FILTER(
SUMMARIZE(
ALL('Dataset'),
'Dataset'[install_date],
"Day1%",
[Day1 %]
),
[install_date]<=_installdate&&[install_date]>=_installdate-2
),
[Day1%]
)
)
return
SUMX(
tab,
[avg]
)
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks! You understood exactly the problem, and your solution works perfect.
I will analyse the formula to understand better what was the problem with mine,
Thanks again,
Regards!
Hi,
Download my PBI file from here.
Hope this helps.
Hi Ashish
Thanks for your answer, but I apply exact the same solution propposed in your files, and the percentages are still bad calculated, I do not understand why 😞
The file:
Hi,
I have already shared my solution file and a screenshot with you. You may not have applied my solution carefully. Try agin.
Hi @gustavo80
Not sure I understand your desired result correct, but DATESINPERIOD is a very tricky function according https://docs.microsoft.com/en-us/dax/datesinperiod-function-dax
The returned table can only contain dates stored in the dates column. So, for example, if the dates column starts from July 1, 2017, and the start_date value is July 1, 2016, the returned table will start from July 1, 2017.
try smth like
Moving_Average_3_Days =
var _curDate = MAX('Dataset'[install_date])
RETURN
CALCULATE (
AVERAGEX ('Dataset', 'Dataset'[Day1 %] ),
FILTER('Dataset',
'Dataset'[install_date] >= _curDate - 3 && 'Dataset'[install_date] <= _curDate
)
)
Thanks for your time, az38!
I tried your solution, and I get exact the same result that I got at first, and with the previous solution suggested. So my conclussion is that the problem is not related to calculate date period, probablly has more to do with the averagex formula.
My desired result is: for every day, I need to have the average Day1% of the 3 previous days.
For example:
For July 5, I want to calculate the average of July 5, July 4 and July 3 Day1%. So it should be the avg between 13.94%, 15.29% amd 14.64% = 14,62% . But instead of that, I'm getting 48.25% or higher values, it makes no sense.
If there is another way easier to calculate it, it will be welcome too 😉
Thanks in advance,
Regards
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 | |
99 | |
76 | |
73 | |
49 |
User | Count |
---|---|
146 | |
108 | |
106 | |
90 | |
62 |