OpenBI Docs Buy

#date

Builds a calendar date out of three numbers: year, month, day of the month.

Group: Dates and times. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

#date(year as number, month as number, day as number) as date
ParameterTypeDescription
yearnumberThe year, 1 to 9999.
monthnumberThe month, 1 to 12.
daynumberThe day of the month: it must exist in that month.

Returns

date. The date; an error when the three numbers are not a day of the calendar.

Remarks

  • A day the month does not have, such as 30 February, is an error rather than a day in the next month.
  • Written in a query, #date(2024, 3, 15) is how M shows a date: the same form comes back as a result.

Examples

An order date

#date(2024, 3, 15)
#date(2024, 3, 15)

Three number columns put together

let
    Orders = #table({"Order", "Year", "Month", "Day"}, {{"A-101", 2024, 3, 15}, {"A-102", 2024, 12, 31}})
in
    Table.AddColumn(Orders, "Date", each #date([Year], [Month], [Day]), type date)
OrderYearMonthDayDate
A-10120243152024-03-15
A-102202412312024-12-31

A day that does not exist

#date(2023, 2, 29)

Result: an error.

[Reason = "Expression.Error", Message = "The Date operation failed because the resulting value falls outside the range of allowed values.", Detail = null]

2023 is not a leap year, so it has no 29 February.

#datetime, Date.From, Date.FromText, List.Dates.

Last updated · OpenBI Studio 0.3.79