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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Rolling average last 3 rows

Hi, I'm new here and I need some help.

I would like to calculate a "W-kee" rolling average over the last 3 rows in the table example as below:

 

jdevalk_0-1633344684963.png

 

So the result should be ((1+4+1)/3=2), but I don't know what DAX formula I need to use.

I think I should use something based on nonblank rows for the W-kee column but I really have no glue.

Please help.

1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, 

According to your description, I can roughly understand your requirement, you can try this measure to get the expected result:

Rolling average =

var _lastrow=CALCULATE(MIN('Table'[SPR]),FILTER(ALL('Table'),[W-kee]=BLANK()&&[W-def]=BLANK()&&[W-mid]=BLANK()&&[W-att]=BLANK()))

return

CALCULATE(AVERAGE('Table'[W-kee]),FILTER(ALL('Table'),[SPR]<=_lastrow-1&&[SPR]>=_lastrow-3))

 

And you can get what you want, like this:

vrobertqmsft_0-1635235935893.png

 

You can download my test pbix file below

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

9 REPLIES 9
v-robertq-msft
Community Support
Community Support

Hi, 

According to your description, I can roughly understand your requirement, you can try this measure to get the expected result:

Rolling average =

var _lastrow=CALCULATE(MIN('Table'[SPR]),FILTER(ALL('Table'),[W-kee]=BLANK()&&[W-def]=BLANK()&&[W-mid]=BLANK()&&[W-att]=BLANK()))

return

CALCULATE(AVERAGE('Table'[W-kee]),FILTER(ALL('Table'),[SPR]<=_lastrow-1&&[SPR]>=_lastrow-3))

 

And you can get what you want, like this:

vrobertqmsft_0-1635235935893.png

 

You can download my test pbix file below

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

Anonymous
Not applicable

Great, that's the one I'm looking for.

Much appreciated!

Tanushree_Kapse
Impactful Individual
Impactful Individual

Hi @Anonymous ,

 

var Rolling Average= CALCULATE(Table[W-knee], FILTER(ALLSELECTED(Table[SPR]), ISONORAFTER( Table[SPR], MAX(Table[SPR]), asc)))
Return  (Rolling Average/ 3)

Mark this as a solution, if I answered your question. Kudos are always appreciated.

Thanks

Anonymous
Not applicable

jdevalk_0-1633351279889.png

 

VahidDM
Super User
Super User

Hi @Anonymous 

 

Try this measure:

Measure=
Var _MaxL = calculate(max(table[SPR]),filter(table,table[W-kee]<>""))
Var _MinL = _MaxL-2
return
Calculate(avarage(table[W-kee]),filter(table,table[SPR]>=_MinL &&table[SPR]<=_MaxL ))

 

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

Appreciate your Kudos!!

 

Anonymous
Not applicable

 

jdevalk_0-1633351852563.png

 

 

jdevalk_1-1633351881401.png

 

 

Hi @Anonymous 

 

What is the format of [SPR] column?

 

Appreciate your Kudos!!

 

Anonymous
Not applicable

Whole number

Hi @Anonymous 

 

Can you share your PBIX file with us (After removing sensetive data)?

 

Appreciate your Kudos!!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.