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

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
Employee
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
Employee
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
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.