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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
sfwannabe
Regular Visitor

Rolling Average for last 3 filtered entries

Hello,

 

I have a table with muiltiple columns, i would like to have a rolling average measure that can bne displayed in a card.

I have a table as shown with a ObjectKey column which is a consecutive increment number.

sfwannabe_0-1654601124474.png

I have a weight column that i would filter using slicers on Line, Scale and Station.

Once i select the slicer values i would like a card to display the rolling average for the last 3 entries for that selection.

sfwannabe_1-1654601172177.png

I have the following code so far, but seems to be far from what i want to achieve.

Rolling average = 
VAR _lastrow = CALCULATE(MIN('processlog'[ObjectKey]),FILTER(ALL('processlog'),[Weight]=BLANK()))
RETURN
CALCULATE(AVERAGE('processlog'[Weight]),FILTER(ALL('processlog'),[ObjectKey]<=_lastrow-1&&[ObjectKey]>=_lastrow-3))

Any advice is most welcome...

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @sfwannabe ,

 

You can try this:

Rolling average = 
VAR _lastrow =
    CALCULATE ( MIN ( 'processlog'[ObjectKey] ), ALLSELECTED ( 'processlog' ) )
RETURN
    CALCULATE (
        AVERAGE ( 'processlog'[Weight] ),
        'processlog'[ObjectKey] >= _lastrow,
        'processlog'[ObjectKey] <= _lastrow + 2
    )

Icey_0-1654830168844.png

 

However, the measure above will only return values when the filtered ObjectKey is consecutive. If the filtered ObjectKey is intermittent, it is suggested to use TOPN function. And it can also work for consecutive ObjectKey.

Rolling average 2 = 
VAR _last3row =
    TOPN ( 3, ALLSELECTED ( processlog ), [ObjectKey], ASC )
RETURN
    AVERAGEX ( _last3row, [Weight] )

Icey_1-1654830352992.png

Icey_2-1654830372348.png

 

 

Best Regards,

Icey

 

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

2 REPLIES 2
sfwannabe
Regular Visitor

So my rolling average is now good... however,  i would like to display the rolling average for each station...

But some stations dont have data, how do i get the filter working on teh card if i cant select the missing data card?

sfwannabe_0-1655073580677.png

 

Icey
Community Support
Community Support

Hi @sfwannabe ,

 

You can try this:

Rolling average = 
VAR _lastrow =
    CALCULATE ( MIN ( 'processlog'[ObjectKey] ), ALLSELECTED ( 'processlog' ) )
RETURN
    CALCULATE (
        AVERAGE ( 'processlog'[Weight] ),
        'processlog'[ObjectKey] >= _lastrow,
        'processlog'[ObjectKey] <= _lastrow + 2
    )

Icey_0-1654830168844.png

 

However, the measure above will only return values when the filtered ObjectKey is consecutive. If the filtered ObjectKey is intermittent, it is suggested to use TOPN function. And it can also work for consecutive ObjectKey.

Rolling average 2 = 
VAR _last3row =
    TOPN ( 3, ALLSELECTED ( processlog ), [ObjectKey], ASC )
RETURN
    AVERAGEX ( _last3row, [Weight] )

Icey_1-1654830352992.png

Icey_2-1654830372348.png

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.