DATESWTD DAX Function (Time Intelligence) Context Transition
Returns a set of dates in the week up to the last date visible in the filter context.
Syntax
| Parameter | Attributes | Description |
|---|---|---|
| Calendar |
The name of a calendar. |
Return values
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.
Remarks
DATESWTD requires a calendar reference. You define a calendar in the model for calendar-based time intelligence. The calendar must tag the Week category. With a date column, or with a calendar that does not tag the Week category, DATESWTD returns an error.
The result has the primary column of each calendar category and the time-related columns of the calendar.
The calendar defines the weeks. DATESWTD returns the dates from the first day of the week to the last date visible in the filter context. For example, if the weeks start on Sunday and the last visible date is a Thursday, the result has five days, from Sunday to Thursday.
With a calendar, the last date of the result depends on the filter context. If the filter context filters the column tagged as Day, the result ends with the last visible day. Otherwise, the result has all the days of the last visible week. For example, with a filter on the DateKey column from August 1 to August 13, 2008, DATESWTD ( ‘Weekly 445’ ) returns all the days from August 10 to August 16, 2008.
A context transition applies. For example, in ADDCOLUMNS over a list of dates, DATESWTD uses the date of the current row.
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.
Examples
-- DATESWTD returns the dates from the first day of the week
-- to the last date visible in the filter context.
-- It requires a calendar that tags the Week category.
-- Weekly 445 is a calendar defined on the Date table.
-- Its weeks start on Sunday and end on Saturday.
-- The result has the primary column of each calendar category
-- and the time-related columns of the calendar.
EVALUATE
CALCULATETABLE (
DATESWTD ( 'Weekly 445' ),
'Date'[Date] = DATE ( 2008, 8, 14 )
)
ORDER BY 'Date'[Date]
| Date | 445 Week Number | 445 Year Week Number | 445 Period Number | 445 Year Period Number | 445 Quarter Number | 445 Year Quarter Number | 445 Year Number |
|---|---|---|---|---|---|---|---|
| 2008-08-10 | 33 | 200833 | 8 | 200808 | 3 | 20083 | 2008 |
| 2008-08-11 | 33 | 200833 | 8 | 200808 | 3 | 20083 | 2008 |
| 2008-08-12 | 33 | 200833 | 8 | 200808 | 3 | 20083 | 2008 |
| 2008-08-13 | 33 | 200833 | 8 | 200808 | 3 | 20083 | 2008 |
| 2008-08-14 | 33 | 200833 | 8 | 200808 | 3 | 20083 | 2008 |
-- Sales WTD returns the sales from the start of the week
-- to the last date visible in the filter context.
-- Week W33-2008 of Weekly 445 starts on Sunday, August 10, 2008.
DEFINE
MEASURE Sales[Sales WTD] =
CALCULATE ( [Sales Amount], DATESWTD ( 'Weekly 445' ) )
EVALUATE
SUMMARIZECOLUMNS (
'Date'[Date],
TREATAS ( { "W33-2008" }, 'Date'[445 Year Week] ),
"Sales Amount", [Sales Amount],
"Sales WTD", [Sales WTD]
)
ORDER BY 'Date'[Date]
| Date | Sales Amount | Sales WTD |
|---|---|---|
| 2008-08-10 | 25856.037000000015 | 25856.037000000015 |
| 2008-08-11 | 10413.719999999992 | 36269.757000000005 |
| 2008-08-12 | 66199.9589999999 | 102469.7159999999 |
| 2008-08-13 | 1524.483 | 103994.19899999989 |
| 2008-08-14 | 18266.229000000003 | 122260.4279999999 |
| 2008-08-15 | 25700.373000000003 | 147960.80099999992 |
| 2008-08-16 | 14246.820000000007 | 162207.62099999993 |
Related functions
Other related functions are:
Last update: Nov 26, 2026 » Contribute » Show contributors
Contributors: Alberto Ferrari, Marco Russo
Microsoft documentation: https://learn.microsoft.com/en-us/dax/dateswtd-function-dax