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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
marco_2020
Helper I
Helper I

Moving Average based on number of samples or time

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

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

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. 

 

Untitled.png

 

Moving avg of last 10 index measure: =
AVERAGEX (
    TOPN (
        10,
        FILTER ( ALL ( Data ), Data[Index] <= MAX ( Data[Index] ) ),
        Data[Index], DESC
    ),
    Data[Value]
)

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
marco_2020
Helper I
Helper I

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.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

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.

Helpful resources

Announcements
November Fabric Update Carousel

Fabric Monthly Update - November 2025

Check out the November 2025 Fabric update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (27)