Date.ToRecord

Date

Returns a record containing the Year, Month, and Day fields of a date value.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Date.ToRecord(date as date) as record

Parameters

NameTypeRequiredDescription
datedateYesA date value to decompose into its components.

Return Value

recordA record with fields Year, Month, and Day as numbers.

Remarks

Date.ToRecord decomposes a date value into a record with three numeric fields: Year, Month, and Day. This is useful when you need all three components at once and want to avoid calling Date.Year, Date.Month, and Date.Day separately in three separate columns. You can expand the record into separate table columns using Table.ExpandRecordColumn.

Note that Date.ToRecord requires a plain date input — it does not accept datetime or datetimezone values. For those types, use DateTime.ToRecord or DateTimeZone.ToRecord. The field names in the returned record are always Year, Month, and Day (capitalized), which you reference when expanding the record.

A common alternative to Date.ToRecord is simply calling the individual accessor functions Date.Year, Date.Month, and Date.Day directly in separate Table.AddColumn calls. Use Date.ToRecord when all three columns are needed at once and a single expansion step is preferable for readability.

Examples

Example 1: Expand date components into separate Year, Month, Day columns

Table.ExpandRecordColumn(
    Table.AddColumn(
        Table.SelectColumns(
            Table.FirstN(Sales, 4),
            {"OrderID", "OrderDate"}
        ),
        "DateParts", each Date.ToRecord([OrderDate])
    ),
    "DateParts",
    {"Year", "Month", "Day"}
)
Result
OrderID
OrderDate
Year
Month
Day
111/15/20242,024115
221/18/20242,024118
332/1/20242,02421
442/10/20242,024210

Example 2: Decompose a specific date into a record

Date.ToRecord(#date(2024, 3, 15))
Result
Field
Value
1Year2,024
2Month3
3Day15

Example 3: Use record fields directly without expansion

Table.AddColumn(
    Table.SelectColumns(Table.FirstN(Sales, 4), {"OrderID", "OrderDate"}),
    "YearMonth",
    each
        let r = Date.ToRecord([OrderDate])
        in Text.From(r[Year]) & "-" & Text.PadStart(Text.From(r[Month]), 2, "0"),
    type text
)
Result
OrderID
OrderDate
YearMonth
111/15/20242024-01
221/18/20242024-01
332/1/20242024-02
442/10/20242024-02

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks