Date.Month
DateReturns the month from a date value.
Syntax
Date.Month(dateTime as any) as nullable numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTime | any | Yes | The date value to extract the month from. |
Return Value
number — The month component of the date (1 through 12).
Remarks
Date.Month returns the month component as a number from 1 (January) to 12 (December) from a date, datetime, or datetimezone value. If the input is null, the function returns null.
Examples
Example 1: Extract the month from OrderDate
Table.AddColumn(
Table.SelectColumns(
Table.FirstN(Sales, 5),
{"OrderID", "OrderDate"}
),
"Month", each Date.Month([OrderDate]), Int64.Type
)Result
OrderID | OrderDate | Month | |
|---|---|---|---|
| 1 | 1 | 1/15/2024 | 1 |
| 2 | 2 | 1/18/2024 | 1 |
| 3 | 3 | 2/1/2024 | 2 |
| 4 | 4 | 2/10/2024 | 2 |
| 5 | 5 | 3/5/2024 | 3 |
Example 2: Group Sales by month
Table.Group(
Sales,
{"OrderDate"},
{{"OrderCount", each Table.RowCount(_), Int64.Type}},
GroupKind.Local,
(a, b) => Byte.From(Date.Month(a[OrderDate]) <> Date.Month(b[OrderDate]))
)Result
OrderDate | OrderCount | |
|---|---|---|
| 1 | 1/15/2024 | 2 |
| 2 | 2/1/2024 | 2 |
| 3 | 3/5/2024 | 2 |
| 4 | 4/1/2024 | 2 |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks