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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Employee
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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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