Daily DAX : Day 429 DATESINPERIOD

Power BI DAX Function: DATESINPERIOD

Description

The DATESINPERIOD function is a Time Intelligence function in DAX that returns a table containing a single column of dates. These dates begin from a specified start date and continue for a given number of intervals (forward or backward in time).

It is commonly used with the CALCULATE function to modify the filter context for time-based calculations, such as rolling totals or moving averages.

Syntax

DATESINPERIOD(, , , )
  • : A reference to a date column (usually from a marked Date table).
  • : The starting date for the period (often MAX('Date'[Date]) for dynamic periods).
  • : The number of intervals to include. Positive for future, negative for past.
  • : The type of interval: DAY, MONTH, QUARTER, or YEAR (no quotes needed).

Use Cases

DATESINPERIOD is ideal for rolling or trailing periods where the end date is dynamic (e.g., the last available date in the current filter context).

  • Calculating sales for the last 12 months (Moving Annual Total).
  • Rolling 3-month averages.
  • Trailing 30-day totals.
  • Year-to-date comparisons excluding the current partial period.

It differs from DATESBETWEEN, which requires both a fixed start and end date.

Examples

1. Last 12 Months Sales (Moving Annual Total)

Sales Last 12 Months = CALCULATE(
    [Total Sales],
    DATESINPERIOD(
        'Date'[Date],
        MAX('Date'[Date]),
        -12,
        MONTH
    )
)

This calculates the total sales from the current date going back 12 months.

2. Last Year Sales (Trailing 1 Year)

Sales Last Year = CALCULATE(
    [Total Sales],
    DATESINPERIOD(
        'Date'[Date],
        MAX('Date'[Date]),
        -1,
        YEAR
    )
)

Returns sales for the previous 365/366 days ending on the latest date in context.

3. Rolling 30-Day Sales

Sales Last 30 Days = CALCULATE(
    [Total Sales],
    DATESINPERIOD(
        'Date'[Date],
        MAX('Date'[Date]),
        -30,
        DAY
    )
)

Useful for daily rolling metrics.

Note: Always use a proper Date table marked as such in Power BI for best results with Time Intelligence functions.

Comments

Popular posts from this blog

Daily DAX : Day 131 SELECTEDMEASURE

Daily DAX : Day 446 INFO.CSDLMETADATA

Daily DAX : Day 453 ENDOFWEEK