16.5A rolling period

You will often follow periods that move forward with each row of the visual, like the last three months or the last twelve months. DATESINPERIOD builds them.

16.5.1DATESINPERIOD

In Excel
ExcelSUMIFS(…,">="&d1,…,"<="&d2)
Match

You need it for a number calculated over a period that moves forward with each row of the visual, like the revenue of the last three months.

DATESINPERIOD returns the days of a period of fixed length, counted from a date.

DATESINPERIOD( <dates>, <start date>, <number>, <period> )

The first argument is the date column of the date table, here Calendar[Date]. The start date is the one the period is counted from. The number sets its length, and it is negative to go back in time. The period is written with a keyword, DAY, MONTH, QUARTER or YEAR. Let us put this measure in a table by month:

Revenue Last 3 Months = CALCULATE( [Revenue], DATESINPERIOD( Calendar[Date], MAX( Calendar[Date] ), -3, MONTH ) )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table
In plain words

“I want the revenue, going back three months from the last date shown.”

MAX( Calendar[Date] ) returns the last date of the row, 3/31/2025 on the March 2025 row. DATESINPERIOD goes back three months from this date, and keeps the days from 1/1/2025 to 3/31/2025.

Month

January 2025

February 2025

March 2025

April 2025

May 2025

June 2025

Table visual, The “Revenue Last 3 Months” measure, from January to May 2025
Month NameRevenue Last 3 Months
January 2025350,000
February 2025350,000
March 2025500,000
April 2025300,000
May 2025300,000
Total300,000

This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.

On the March row, January, February and March 2025 make 200,000 + 150,000 + 150,000. On the January row, the period goes back to November 2024, which brings 150,000.

Tips
  • If the total surprises you, that is normal, it is not the sum of the rows. The slicer keeps January to May 2025. On the “Total” row, MAX returns 5/31/2025, and the measure takes March, April and May again, 300,000.

  • Divided by 3, this measure gives an average over three months. This is called a moving average.

Practice

Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.

  1. Direct useMeasureDifficulty

    A gym already has a “Sessions” measure, the sum of the “Sessions” column. The “Days” date table, with its “Date” column, is marked and linked to the “Sessions” table. In a visual by month, write the “Sessions Last 3 Months” measure, the sessions of the three months that end on the last date of the row.

    Sessions
    DateSessions
    2/15/2026100
    3/15/2026120
    4/15/202690
    5/15/2026110

    Which formula should you write for “Sessions Last 3 Months”?

  2. Combined useMeasureDifficulty

    A weather station already has a “Rain” measure, which adds up the rain that fell, in millimeters. The “Days” date table, with its “Date” column, is marked and linked to the readings table. In a visual by month, write the “Average Rain over 12 Months” measure, the rain of the twelve months that end on the last date of the row, divided by 12, with DIVIDE.

The rest of this lesson is part of izyDAX Pro

You have just read the first section. The next one, its animations, the exercises and the summary are waiting for you with izyDAX Pro, in a single payment.