We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

More Time Functions

Before we move on, it's worth mentioning some other particularly useful time functions:

  • TOTALYTD: Calculates year-to-date values. Useful for tracking annual performance and cumulative growth.
  • DATEADD: Shifts the date context by a number of days, months, quarters, or years. Perfect for week-over-week or month-over-month comparisons.
  • DATESINPERIOD: Returns a rolling range of dates. Essential for things like rolling 7-day, 30-day, or 90-day performance.
  • DATEDIFF: Calculates the difference between two dates in days, months, or years. Great for calculating age, tenure, or time to complete tasks.
  • DATE: Creates a date from year, month, and day values. Useful for constructing specific dates in your data model.
  • TODAY: Returns the current date. Handy for dynamic reports that need to show today's data.

If you learn these, you can build almost every core time-based metric.

For a more complete list, check the docs here.

Example of Dates in Period

num_sales_in_2026 =
CALCULATE (
    SUM ( sales[quantity] ),
    DATESINPERIOD ( dates[date], DATE( 2026, 01, 01 ), 1, YEAR )
)
  • dates[date] is a reference to a column containing date values that have a relationship that ties back to our sales
  • DATE( 2026, 01, 01 ) is the start date
  • 1 is the number of intervals
  • YEAR is the interval duration

Assignment

  1. Use CALCULATE with [total_revenue] as its first argument – measures are referenced directly, not wrapped in SUM().

Save the project and, from the course directory, submit the CLI tests.