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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Calculating Average over previous periods according to filter

Hi, everybody.

I worked with OBIEE for a few years, and I'm starting with Power BI.
I'm currently struggling with its formula sintax on front-end, and I kindly need some help with one quite simple calculation, please:

For one particular Dashboard page, I only have one page filter, which is "Week" ("Week 01", "Week 02", "Week 03", etc.)

I have a metric "Order Value", and I actually need is to calculate the Average Sum of the Order Value for the current week and the 3 previous ones.
I mean, if I choose "Week 31" on the page filter, the measure shoud calculate the Average Sum from Weeks 31, 30, 29 and 28.

 

Just as a reference, in OBIEE I would define a presentation variable for the Week Filter, and I'd create a Measure that would consider the selected week through the variable on the formula and summarize the Order Value for current week + (current week-1) + (current week -2), etc, and then apply AVERAGE on it, but that doesn't seem like a workaround applicable for Power BI.


Thank you very much in advance.
I really appreciate your help.

Looking forward for your reply

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello, Daniel.

I wasn't aware of the functions "ALL" and "SELECTEDVALUE".
It worked out just fine.

 

Thank you very much!
You're a life saver.

 

Best regards.

View solution in original post

2 REPLIES 2
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

Based on my test, you could refer to below steps:

Sample data:

1.PNG

Create an Index column:

Index = RANKX('Table1',FIRSTNONBLANK('Table1'[Week],'Table1'[Week]),,ASC,Dense)

1.PNG

Create a measure:

Measure = CALCULATE(AVERAGE(Table1[Value]),FILTER(ALL('Table1'),'Table1'[Index]>=SELECTEDVALUE(Table1[Index])-3&&'Table1'[Index]<=SELECTEDVALUE(Table1[Index])))

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hello, Daniel.

I wasn't aware of the functions "ALL" and "SELECTEDVALUE".
It worked out just fine.

 

Thank you very much!
You're a life saver.

 

Best regards.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI 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.

Top Solution Authors
Top Kudoed Authors