The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hello All,
I attempting to get the average sales for the last 7 days of a sales table like this:
Item | Date | QTY |
AA | 1/1 | 1 |
AA | 1/2 | 2 |
AA | 1/4 | 2 |
AA | 1/6 | 2 |
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:
Item | 7 Day Average |
AA | 1 |
Solved! Go to Solution.
I forgot to mention, I have a calendar table connected to this sales table
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 )
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 )
I forgot to mention, I have a calendar table connected to this sales table