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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
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.

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.
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.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.