The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hello, I have found many threads about moving average but they are all based on date filters (e.g. moving average based on a time windows of at least 1 day). In my report I need to implement a moving average based on a specific number of samples (e.g. buffer size of 10 samples) or based on hours (time window of 3 hours).
How is this possible?
Thank you in advance
Solved! Go to Solution.
Hi @marco_2020 ,
You can try the following dax:
Meaure =
VAR currDate =
MAX ( Table[LOAD_END_TIME] )
RETURN
CALCULATE (
AVERAGE ( Table[SHOVEL_TRUCK_DIFFERENCE] ),
FILTER (
ALLSELECTED ( Table ),
[LOAD_END_TIME] <= currDate
&& DATEDIFF ( [LOAD_END_TIME], currDate, SECOND ) <= 1800
)
)
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @marco_2020 ,
You can try the following dax:
Meaure =
VAR currDate =
MAX ( Table[LOAD_END_TIME] )
RETURN
CALCULATE (
AVERAGE ( Table[SHOVEL_TRUCK_DIFFERENCE] ),
FILTER (
ALLSELECTED ( Table ),
[LOAD_END_TIME] <= currDate
&& DATEDIFF ( [LOAD_END_TIME], currDate, SECOND ) <= 1800
)
)
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello,
really thank you.
My last concern is regarding computing moving average in a dataset over datetime column considering for example last 3 hours as time window. Is this possible?
Thanks
Marco
Hi,
I do not know how your data model looks like, but I think it is possible by using dim-time table for the calculation of 3 hrs segment.
Thank you.
Hi,
I am not sure if I understood your question correctly.
I tried to create a sample pbix file like below, and the below sample is showing last 10 samples moving avg.
Moving avg of last 10 index measure: =
AVERAGEX (
TOPN (
10,
FILTER ( ALL ( Data ), Data[Index] <= MAX ( Data[Index] ) ),
Data[Index], DESC
),
Data[Value]
)
User | Count |
---|---|
25 | |
10 | |
8 | |
6 | |
5 |
User | Count |
---|---|
31 | |
11 | |
10 | |
10 | |
9 |