Others

Create a 12-Month Moving Average of a DAX Measure in Power BI

Algirdas JasaitisAlgirdas Jasaitis Dec 2, 2026 869 views

Question details

Calculate a rolling 12-month average of a distinct transaction measure in Power BI.

Create a 12-Month Moving Average of a DAX Measure in Power BI
Product
Microsoft Power BI
Device & OS
not provided
Scenario
A report needs to show the average monthly distinct transaction count over a rolling 12-month period.
Observed behavior
The desired chart displays a moving average calculated from monthly distinct transaction counts using a dedicated date table.
Before you start

Confirm that your transaction table has a transaction ID and a date column, and identify the measure you want to average. Use date-only values for the relationship and ensure your date table covers the reporting period.

Solution 1Recommended

Use a date table and DAX to average monthly transaction counts

Use DATESINPERIOD to define the rolling window and AVERAGEX to average the distinct transaction measure by month.

The example averages monthly distinct counts, not the distinct count across the entire 12-month window. Replace the example table and column names with those in your model.

1
Create a date table

In Power BI Desktop, select Modeling > New table and enter a calendar covering your reporting period, for example: Date = CALENDAR(DATE(2023, 1, 1), DATE(2026, 12, 31)). Adjust the dates to suit your data.

2
Add a month column

Select the Date table, choose New column, and enter: MonthStart = DATE(YEAR('Date'[Date]), MONTH('Date'[Date]), 1). This gives each month a sortable date value.

3
Mark and relate the table

Select the Date table and use Table tools > Mark as date table, choosing Date[Date]. In Model view, create an active one-to-many relationship from Date[Date] to Transactions[TransactionDate].

4
Create the distinct count measure

Select Modeling > New measure and enter: Distinct Transactions = DISTINCTCOUNT(Transactions[TransactionID]). If you already have a suitable measure, use its name in the next step instead.

5
Create the rolling average

Select Modeling > New measure and enter: 12-Month Average = CALCULATE(AVERAGEX(VALUES('Date'[MonthStart]), CALCULATE([Distinct Transactions])), DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -12, MONTH)).

6
Build the chart

Add a line chart in Report view. Place Date[MonthStart] on the X-axis and [12-Month Average] on the Y-axis. Use the month column itself rather than its automatic date hierarchy.

Use a date table and DAX to average monthly transaction counts
Check partial periods and blank months: Early points may use fewer than 12 months if the date table or data does not extend far enough back. AVERAGEX ignores months where the measure returns blank; use COALESCE([Distinct Transactions], 0) inside the iterator if blank months should count as zero.
Free Microsoft Office alternative

Explore transaction data in WPS Spreadsheets

WPS Office is a free, lightweight Office alternative with a familiar interface for working with exported transaction data. It supports common Microsoft Excel formats, making it easy to move spreadsheets between applications. It does not edit or calculate Power BI DAX measures.

Review exported transaction data in a familiar spreadsheet interfaceOpen and save Microsoft Excel XLSX and XLS filesUse a free, lightweight alternative for everyday spreadsheet work
microsoft office alternative - wps office

Frequently Asked Questions

Why should I use a separate date table?

A continuous date table provides consistent date filtering for DATESINPERIOD. In Power BI Desktop, mark it through Table tools > Mark as date table and relate its date column to the transaction date.

Is this the same as a distinct count over 12 months?

No. The measure calculates a distinct count for each month and then averages those monthly counts. A single transaction ID appearing in multiple months can contribute to more than one monthly count.

Why does the first chart point use fewer than 12 months?

The available date table or transaction history may not cover the full preceding period. Check the Date table range and the earliest transaction date before interpreting early values.

How do I include months with no transactions as zero?

Replace [Distinct Transactions] inside the AVERAGEX calculation with COALESCE([Distinct Transactions], 0). This makes blank monthly results contribute zero to the average.

Which date field should I put on the chart axis?

Use Date[MonthStart] from the related date table on the X-axis. It distinguishes months across years and provides a chronological monthly axis.