DATESBETWEEN DAX Function (Time Intelligence)

Returns the dates between two given dates.

Syntax

DATESBETWEEN ( <Dates>, <StartDate>, <EndDate> )
Parameter Attributes Description
Dates

The name of a column containing dates or a calendar reference.

StartDate

Start date. With a calendar, use the same data type as the column tagged as Day.

EndDate

End date. With a calendar, use the same data type as the column tagged as Day.

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 a reference to a date column or a calendar reference. You define a calendar in the model for calendar-based time intelligence.

With a date column, the result has one column of dates. The result includes only dates that exist in the Dates column.

With a calendar, the result has the primary column of each calendar category and the time-related columns of the calendar.

The dates used as StartDate and EndDate are inclusive. For example, if the sales occurred on September 1 and you use September 1 as StartDate, the sales on September 1 are counted.

If StartDate is BLANK, DATESBETWEEN starts from the first date in the Dates column. With a calendar, it starts from the first value in the column tagged as Day.

If EndDate is BLANK, DATESBETWEEN ends with the last date in the Dates column. With a calendar, it ends with the last value in the column tagged as Day.

If StartDate is later than EndDate, the result is an empty table.

With a calendar, StartDate and EndDate must have the same data type and the same format as the column tagged as Day. If a value does not exist in that column, DATESBETWEEN uses it as BLANK. For example, a date with a time part, or a date that is outside the calendar, gives the first or the last date of the calendar. Thus, with a calendar, two dates after the last date return all the dates. With a date column, the same dates return an empty table.

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.

» 5 related articles

Examples

--  DATESBETWEEN returns the dates between the boundaries specified.
--  The boundaries are both included in the result.
--  If EndDate is earlier than StartDate, the result is an empty table.
EVALUATE
VAR StartDate = DATE ( 2008, 08, 25 )
VAR EndDate =   DATE ( 2008, 08, 31 )
RETURN
    DATESBETWEEN ( 'Date'[Date], StartDate, EndDate )
ORDER BY [Date]
Date
2008-08-25
2008-08-26
2008-08-27
2008-08-28
2008-08-29
2008-08-30
2008-08-31
--  Using BLANK for one boundary means use MIN/MAX of available dates.
--  This query returns all the dates from Jan 1, 2005 (first date in the Date table)
--  and August 31, 2008
EVALUATE
VAR StartDate = BLANK ()
VAR EndDate =   DATE ( 2008, 08, 31 )
RETURN
    DATESBETWEEN ( 'Date'[Date], StartDate, EndDate )
ORDER BY [Date]
--  DATESBETWEEN returns dates that exist in the Date table.
--  A date lower than the minimum makes DATESBETWEEN start
--  from the min value anyway.
--  The content of the Date table starts from Jan 1, 2005.
EVALUATE
VAR StartDate = DATE ( 2004, 01, 01 )   -- Lower than MIN ( 'Date'[Date] )
VAR EndDate =   DATE ( 2005, 01, 6 )
RETURN
    DATESBETWEEN ( 'Date'[Date], StartDate, EndDate )
ORDER BY [Date]
Date
2005-01-01
2005-01-02
2005-01-03
2005-01-04
2005-01-05
2005-01-06
--  In this example we compute the moving average of [Sales Amount] over 30 days
--  Moving periods are easier to compute using DATESINPERIOD, anyway.
DEFINE
    MEASURE Sales[Sales Last 30D] =
        VAR Last30D =
            DATESBETWEEN ( 
                'Date'[Date], 
                MAX ( 'Date'[Date] ) - 29,  -- boundaries are included, this is why we use 29
                MAX ( 'Date'[Date] )        -- to obtain 30 days
            )
        VAR Result =
            CALCULATE (
                [Sales Amount] / 30,
                Last30D
            )
        RETURN
            Result
EVALUATE
SUMMARIZECOLUMNS (
    'Date'[Date],
    "Sales Amount", [Sales Amount],
    "Sales 30D", [Sales Last 30D]
)
ORDER BY [Date]
--  With a calendar, DATESBETWEEN returns all the columns of the calendar:
--  the primary column of each category and the time-related columns.
--  Gregorian is a calendar defined on the Date table.
EVALUATE
VAR StartDate = DATE ( 2008, 08, 25 )
VAR EndDate =   DATE ( 2008, 08, 31 )
RETURN
    DATESBETWEEN ( Gregorian, StartDate, EndDate )
ORDER BY 'Date'[Date]
Date Month Number Calendar Year Month Number Calendar Year Quarter Number Calendar Year Number
2008-08-25 8 200808 20083 2008
2008-08-26 8 200808 20083 2008
2008-08-27 8 200808 20083 2008
2008-08-28 8 200808 20083 2008
2008-08-29 8 200808 20083 2008
2008-08-30 8 200808 20083 2008
2008-08-31 8 200808 20083 2008
--  With a calendar, a StartDate or EndDate that does not exist
--  in the Day column works like BLANK: DATESBETWEEN uses
--  the first or the last date of the calendar.
--  With a date column, DATESBETWEEN uses the dates as they are.
--  The Date table contains the dates from Jan 1, 2005 to Dec 31, 2011.
EVALUATE
VAR StartWithTime = DATE ( 2008, 08, 25 ) + TIME ( 12, 0, 0 )
VAR EndDate = DATE ( 2008, 08, 31 )
VAR ColumnWithTime = DATESBETWEEN ( 'Date'[Date], StartWithTime, EndDate )
VAR CalendarWithTime = DATESBETWEEN ( Gregorian, StartWithTime, EndDate )
VAR ColumnAfterData = DATESBETWEEN ( 'Date'[Date], DATE ( 2015, 1, 1 ), DATE ( 2015, 12, 31 ) )
VAR CalendarAfterData = DATESBETWEEN ( Gregorian, DATE ( 2015, 1, 1 ), DATE ( 2015, 12, 31 ) )
RETURN
    UNION (
        ROW ( "Case", "StartDate with time", "Dates", "Date column", "First", MINX ( ColumnWithTime, 'Date'[Date] ), "Last", MAXX ( ColumnWithTime, 'Date'[Date] ), "Days", COUNTROWS ( ColumnWithTime ) ),
        ROW ( "Case", "StartDate with time", "Dates", "Calendar", "First", MINX ( CalendarWithTime, 'Date'[Date] ), "Last", MAXX ( CalendarWithTime, 'Date'[Date] ), "Days", COUNTROWS ( CalendarWithTime ) ),
        ROW ( "Case", "Dates after the data", "Dates", "Date column", "First", MINX ( ColumnAfterData, 'Date'[Date] ), "Last", MAXX ( ColumnAfterData, 'Date'[Date] ), "Days", COUNTROWS ( ColumnAfterData ) ),
        ROW ( "Case", "Dates after the data", "Dates", "Calendar", "First", MINX ( CalendarAfterData, 'Date'[Date] ), "Last", MAXX ( CalendarAfterData, 'Date'[Date] ), "Days", COUNTROWS ( CalendarAfterData ) )
    )
Case Dates First Last Days
StartDate with time Date column 2008-08-25 2008-08-31 7
StartDate with time Calendar 2005-01-01 2008-08-31 1339
Dates after the data Date column (Blank) (Blank) (Blank)
Dates after the data Calendar 2005-01-01 2011-12-31 2556
--  Life-to-date sales with a date column and with a calendar.
--  The query filters Sundays: Day of Week is not part of the Gregorian calendar.
--  With the date column of a table marked as a date table, CALCULATE removes
--  all the filters on the Date table, Day of Week included.
--  With the calendar, CALCULATE removes only the filters on the calendar columns.
--  The filter on Day of Week stays: Sales LTD Calendar sums only Sundays.
DEFINE
    MEASURE Sales[Sales LTD Date] =
        CALCULATE (
            [Sales Amount],
            DATESBETWEEN ( 'Date'[Date], BLANK (), MAX ( 'Date'[Date] ) )
        )
    MEASURE Sales[Sales LTD Calendar] =
        CALCULATE (
            [Sales Amount],
            DATESBETWEEN ( Gregorian, BLANK (), MAX ( 'Date'[Date] ) )
        )
EVALUATE
SUMMARIZECOLUMNS (
    'Date'[Calendar Year Month],
    'Date'[Calendar Year Month Number],
    TREATAS ( { "CY 2007" }, 'Date'[Calendar Year] ),
    TREATAS ( { "Sunday" }, 'Date'[Day of Week] ),
    "Sales Amount", [Sales Amount],
    "Sales LTD Date", [Sales LTD Date],
    "Sales LTD Calendar", [Sales LTD Calendar]
)
ORDER BY 'Date'[Calendar Year Month Number]
Calendar Year Month Calendar Year Month Number Sales Amount Sales LTD Date Sales LTD Calendar
January 2007 200701 71441.9874999996 762765.853499999 71441.9874999997
February 2007 200702 125703.5402 1597596.0356 197145.5277
March 2007 200703 156957.4776 2462500.9778 354103.0053
April 2007 200704 207433.3726 3761906.1573 561536.3779
May 2007 200705 103784.1 4624291.8184 665320.4779
June 2007 200706 131817.94 5480281.9264 797138.4179
July 2007 200707 111575.662 6569466.6524 908714.0799
August 2007 200708 147062.713 7434515.62039999 1055776.7929
September 2007 200709 214781.885000001 8578521.961 1270558.6779
October 2007 200710 129280.62 9441378.79699999 1399839.2979
November 2007 200711 52165.3634999998 10216429.9655 1452004.6614
December 2007 200712 185099.491 11303094.1775 1637104.1524

Related articles

Learn more about DATESBETWEEN in the following articles:

Last update: Oct 20, 2026   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

Microsoft documentation: https://docs.microsoft.com/en-us/dax/datesbetween-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 DATESBETWEEN? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.


This site is protected by reCAPTCHA.