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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Get the average sales value based on last 7 days but if there are no sales there is no entry

Hello All,

 

I attempting to get the average sales for the last 7 days of a sales table like this:

 

ItemDateQTY
AA1/11
AA1/22
AA1/42
AA1/62

 

The problem i'm running into is that If you Average() or Averagex() and use whichever date filter, you get the average of values that exist. Ideally, I would want the average including the 0 sales on 1/5,1/7 and 1/3 but those transaction don't appear in my table.

 

I would want a dax expression to result to this:

 

Item7 Day Average
AA1
2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

I forgot to mention, I have a calendar table connected to this sales table

View solution in original post

Anonymous
Not applicable

Found a solution! 

 

 

7 Day Moving Average =

VAR SelectedDate = MAX(Calendar[Date])

VAR StartDate = SelectedDate - 6 VAR TotalSales = CALCULATE ( SUM ( Sales[Amount] ), DATESINPERIOD ( Calendar[Date], StartDate, SelectedDate, DAY ) )

VAR TotalDays = COUNTROWS ( DATESINPERIOD ( Calendar[Date], StartDate, SelectedDate, DAY ) )

 

RETURN DIVIDE ( TotalSales, TotalDays, 0 )

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Found a solution! 

 

 

7 Day Moving Average =

VAR SelectedDate = MAX(Calendar[Date])

VAR StartDate = SelectedDate - 6 VAR TotalSales = CALCULATE ( SUM ( Sales[Amount] ), DATESINPERIOD ( Calendar[Date], StartDate, SelectedDate, DAY ) )

VAR TotalDays = COUNTROWS ( DATESINPERIOD ( Calendar[Date], StartDate, SelectedDate, DAY ) )

 

RETURN DIVIDE ( TotalSales, TotalDays, 0 )

Anonymous
Not applicable

I forgot to mention, I have a calendar table connected to this sales table

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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