DATESMTD DAX Function (Time Intelligence)  Context Transition

Returns a set of dates in the month up to the last date visible in the filter context.

Syntax

DATESMTD ( <Dates> )
Parameter Attributes Description
Dates

The name of a column containing dates, a single column table containing dates, or a calendar reference.

Return values

Table An entire table or a table with one or more columns.

For a date column, a table containing a single column of date values. For a calendar, a table containing the primary column of each calendar category and the time-related columns.

Notes

In order to use any time intelligence calculation, you need a well-formed date table. The Date table must satisfy the following requirements:

  • All dates need to be present for the years required. The Date table must always start on January 1 and end on December 31, including all the days in this range. If the report only references fiscal years, then the date table must include all the dates from the first to the last day of a fiscal year. For example, if the fiscal year 2008 starts on July 1, 2007, then the Date table must include all the days from July 1, 2007 to June 30, 2008.
  • There needs to be a column with a DateTime or Date data type containing unique values. This column is usually called Date. Even though the Date column is often used to define relationships with other tables, this is not required. Still, the Date column must contain unique values and should be referenced by the Mark as Date Table feature. In case the column also contains a time part, no time should be used – for example, the time should always be 12:00 am.
  • The Date table must be marked as a date table in the model, in case the relationship between the Date table and any other table is not based on the Date.
The result of time intelligence functions has the same data lineage as the date column or table provided as an argument.

Remarks

The dates argument can be any of the following:

  • A reference to a date/time column. In this case, a context transition applies because the column reference is replaced by
  • A table expression that returns a single column of date/time values.
  • A Boolean expression that defines a single-column table of date/time values.
  • A calendar reference. You define a calendar in the model for calendar-based time intelligence. With a calendar, the result has the primary column of each calendar category and the time-related columns of the calendar. Also in this case, a context transition applies.

The result table includes only dates that exist in the dates column.

With a date column, the syntax:

DATESMTD ( <Dates> ) 

corresponds to:

DATESBETWEEN ( 
    <Dates>, 
    STARTOFMONTH ( LASTDATE ( <Dates> ) ),
    LASTDATE ( <Dates> ) 
)

With a calendar, the last date of the result depends on the columns that the filter context filters:

  • If the filter context filters the column tagged as Day, the result ends with the last visible day.
  • If the filter context filters a column of another category, for example a week or a month column, the result ends with the last day of the last visible period of that category. The result does not go past the end of the month.
  • If the filter context filters only columns that no calendar tags, for example the day of the week, the result has all the days of the month that includes the last visible date.

For example, with a filter on the DateKey column from August 1 to August 13, 2008, DATESMTD ( Gregorian ) returns August 1 to August 31, 2008, and DATESMTD ( ‘Date'[Date] ) returns August 1 to August 13, 2008. With a date column, the result always ends with the last visible date.

If the filter context filters a column that another calendar tags as Week, a calendar without the Week category returns an error.

With a calendar, CALCULATE removes only the filters on the columns of the calendar. The filters on the other columns of the date table stay, for example a filter on the day of the week. With the date column of a table marked as a date table, CALCULATE removes all the filters on the date table.

This function is not supported in DirectQuery mode when used in calculated columns or row-level security (RLS) rules.

» 1 related article
» 3 related functions

Examples

--  DATESMTD returns the dates from the first day of the currently selected
--  month to the last date visible in the filter context.
EVALUATE
CALCULATETABLE (
    DATESMTD ( 'Date'[Date] ),
    'Date'[Date] = DATE ( 2007, 5, 6 )
)
ORDER BY [Date] ASC
Date
2007-05-01
2007-05-02
2007-05-03
2007-05-04
2007-05-05
2007-05-06
--  If the selection contains larger periods, it returns the MTD using
--  the end of the entire period.
--  The result is always a single-column table.
EVALUATE
    CALCULATETABLE ( 
        DATESMTD ( 'Date'[Date] ),
        'Date'[Date] >= DATE ( 2007, 2, 5 ) 
            && 'Date'[Date] <= DATE ( 2007, 5, 6 ) 
    )
ORDER BY [Date] ASC
Date
2007-05-01
2007-05-02
2007-05-03
2007-05-04
2007-05-05
2007-05-06
--  All time intelligence functions are designed to return a table
--  to be easily used in CALCULATE as a filter.
EVALUATE
{
    CALCULATE (
        CALCULATE (
            [Sales Amount],
            DATESMTD ( 'Date'[Date] )       -- 2007-05-01 : 2007-05-06
        ),
        'Date'[Date] = DATE ( 2007, 5, 6 )
    )
}
Value
90,580.47
--  With a calendar, DATESMTD uses the months of that calendar.
--  Gregorian and Weekly 445 are calendars defined on the Date table.
--  In Weekly 445, a month is a period of 4 or 5 weeks from Sunday to Saturday.
--  Period P08-2008 starts on July 27, 2008, and August 2008 starts on August 1.
DEFINE
    MEASURE Sales[Sales MTD] =
        CALCULATE ( [Sales Amount], DATESMTD ( Gregorian ) )
    MEASURE Sales[Sales MTD 445] =
        CALCULATE ( [Sales Amount], DATESMTD ( 'Weekly 445' ) )
EVALUATE
SUMMARIZECOLUMNS (
    'Date'[Date],
    DATESBETWEEN ( 'Date'[Date], DATE ( 2008, 7, 25 ), DATE ( 2008, 8, 3 ) ),
    "Sales Amount", [Sales Amount],
    "Sales MTD", [Sales MTD],
    "Sales MTD 445", [Sales MTD 445]
)
ORDER BY 'Date'[Date]
Date Sales Amount Sales MTD Sales MTD 445
2008-07-25 22869.0 737607.8700000001 807032.4100000001
2008-07-26 48029.418000000034 785637.2880000002 855061.8280000002
2008-07-27 2540.2229999999918 788177.5110000002 2540.2229999999918
2008-07-28 21296.35800000001 809473.8690000002 23836.581000000002
2008-07-29 23677.20899999998 833151.0780000002 47513.78999999998
2008-07-30 36843.39000000001 869994.4680000002 84357.18
2008-07-31 20552.93999999999 890547.4080000003 104910.12
2008-08-01 9146.259999999993 9146.259999999993 114056.37999999998
2008-08-02 20106.693000000036 29252.95300000003 134163.073
2008-08-03 378.5499999999999 29631.503000000026 134541.62300000002

Related articles

Learn more about DATESMTD in the following articles:

  • Time Intelligence in Power BI Desktop

    In Power BI Desktop (as of February 2016) you have to use DAX to apply calculations over dates (such as year-to-date, year-over-year, and others), but you do not have the Mark as Date Table feature. This article describes which scenarios are impacted and the possible workarounds. » Read more

Related functions

Other related functions are:

Last update: Nov 10, 2026   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

Microsoft documentation: https://learn.microsoft.com/en-us/dax/datesmtd-function-dax

2018-2026 © SQLBI. All rights are reserved. Information coming from Microsoft documentation is property of Microsoft Corp. » Contact us   » Privacy Policy & Cookies

Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.

Passed by Expression

This parameter is passed by expression and can be evaluated multiple times in different evaluation contexts.

Iterator

Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.

Deprecated

This function is deprecated. Jump to the Alternatives section to see the function to use.

Volatile

A volatile function may return a different result every time you call it, even if you provide the same arguments. Click to read more.

Deprecated

This parameter is deprecated and its use is not recommended.

DirectQuery compatibility

Limitations are placed on DAX expressions allowed in measures and calculated columns.
The state below shows the DirectQuery compatibility of the DAX function.

Contribute

Want to improve the content of DATESMTD? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.