DAX code
Moving Average =
VAR LastDate = MAX('Date'[Date])
VAR Last7Days = DATESINPERIOD('Date'[Date], LastDate, -7, DAY)
RETURN
AVERAGEX(Last7Days, CALCULATE([Total Sales]))
Averages daily sales over the trailing 7 days ending on the current date filter context.
Type your table and column names once. Every measure below updates.
Moving Average =
VAR LastDate = MAX('Date'[Date])
VAR Last7Days = DATESINPERIOD('Date'[Date], LastDate, -7, DAY)
RETURN
AVERAGEX(Last7Days, CALCULATE([Total Sales]))
Generate a Power BI date table
Change -7 to whatever window length your moving average should use.
Browse all 175 measures in the Power BI DAX Measures Library, or search the library for something similar to Moving Average.