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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Calculate past 5 week Average

I was trying to generate a 5-week average volume. Does anyone know why the first formula work but not the second one? 

 

Vol Avg5WK = calculate(Divide(SUM('2014Data'[#Shipments]),5),FILTER(all('2014Data'),'2014Data'[WeekNum]>=MAX('2014Data'[WeekNum])-5 && '2014Data'[WeekNum]<=MAX('2014Data'[WeekNum])-1))

 

Vol Avg5WK = calculate(Divide(SUM('2014Data'[#Shipments]),5),FILTER('2014Data','2014Data'[WeekNum]>=MAX('2014Data'[WeekNum])-5 && '2014Data'[WeekNum]<=MAX('2014Data'[WeekNum])-1))

 

The difference is I removed All() from Filter function.

 

Many thanks!

 

 

1 ACCEPTED SOLUTION
Eric_Zhang
Microsoft Employee
Microsoft Employee


@Anonymous wrote:

I was trying to generate a 5-week average volume. Does anyone know why the first formula work but not the second one? 

 

Vol Avg5WK = calculate(Divide(SUM('2014Data'[#Shipments]),5),FILTER(all('2014Data'),'2014Data'[WeekNum]>=MAX('2014Data'[WeekNum])-5 && '2014Data'[WeekNum]<=MAX('2014Data'[WeekNum])-1))

 

Vol Avg5WK = calculate(Divide(SUM('2014Data'[#Shipments]),5),FILTER('2014Data','2014Data'[WeekNum]>=MAX('2014Data'[WeekNum])-5 && '2014Data'[WeekNum]<=MAX('2014Data'[WeekNum])-1))

 

The difference is I removed All() from Filter function.

 

Many thanks!

 

 


@Anonymous

It is the Context that make those two measures show differently, see Understanding Evaluation Contexts in DAX. The ALL function returns all the rows in a table, or all the values in a column, ignoring any filters that might have been applied. ALL function is useful for clearing filters and creating calculations on all the rows in a table. For example, if the context refers to all rows, eg in a Card visual, Those two measure would give the same output.

View solution in original post

1 REPLY 1
Eric_Zhang
Microsoft Employee
Microsoft Employee


@Anonymous wrote:

I was trying to generate a 5-week average volume. Does anyone know why the first formula work but not the second one? 

 

Vol Avg5WK = calculate(Divide(SUM('2014Data'[#Shipments]),5),FILTER(all('2014Data'),'2014Data'[WeekNum]>=MAX('2014Data'[WeekNum])-5 && '2014Data'[WeekNum]<=MAX('2014Data'[WeekNum])-1))

 

Vol Avg5WK = calculate(Divide(SUM('2014Data'[#Shipments]),5),FILTER('2014Data','2014Data'[WeekNum]>=MAX('2014Data'[WeekNum])-5 && '2014Data'[WeekNum]<=MAX('2014Data'[WeekNum])-1))

 

The difference is I removed All() from Filter function.

 

Many thanks!

 

 


@Anonymous

It is the Context that make those two measures show differently, see Understanding Evaluation Contexts in DAX. The ALL function returns all the rows in a table, or all the values in a column, ignoring any filters that might have been applied. ALL function is useful for clearing filters and creating calculations on all the rows in a table. For example, if the context refers to all rows, eg in a Card visual, Those two measure would give the same output.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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