Date.WeekOfMonth
DateReturns the week number within the month (1–6) for the given date.
Syntax
Date.WeekOfMonth(dateTime as any, optional firstDayOfWeek as nullable number) as nullable numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTime | any | Yes | A date, datetime, or datetimezone value. |
firstDayOfWeek | number | No | A Day.* constant specifying the first day of the week. Defaults to Day.Sunday (0). Use Day.Monday (1) for ISO weeks. |
Return Value
number — An integer from 1 to 6 representing the week number within the month.
Remarks
Date.WeekOfMonth returns the week number within the calendar month, starting from 1. Week 1 is always the week that contains the first day of the month. Partial weeks at the start and end of the month count as full weeks — so the first day of the month always falls in week 1, and the last day may fall in week 4, 5, or (rarely) 6. If the input is null, the function returns null.
The optional firstDayOfWeek parameter determines which day begins a new week. The default is Day.Sunday (0). Use Day.Monday (1) for ISO-style Monday-to-Sunday weeks. Always use the Day.* enum constants rather than integer literals to keep your code self-documenting.
Date.WeekOfMonth is most useful for weekly bucketing within a month — for example, grouping orders by "Week 1 of Jan", "Week 2 of Jan", and so on. Combine with Date.Year and Date.Month to build a full weekly period label. For week numbers within the year, use Date.WeekOfYear instead.
Examples
Example 1: Add week-of-month to Sales table
Table.AddColumn(
Table.SelectColumns(
Table.FirstN(Sales, 5),
{"OrderID", "OrderDate"}
),
"WeekOfMonth", each Date.WeekOfMonth([OrderDate], Day.Sunday), Int64.Type
)OrderID | OrderDate | WeekOfMonth | |
|---|---|---|---|
| 1 | 1 | 1/15/2024 | 3 |
| 2 | 2 | 1/18/2024 | 3 |
| 3 | 3 | 2/1/2024 | 1 |
| 4 | 4 | 2/10/2024 | 2 |
| 5 | 5 | 3/5/2024 | 1 |
Example 2: Week of month using Monday as start of week
#table(
type table [Date = date, WeekOfMonth = number],
{{#date(2024, 3, 15), Date.WeekOfMonth(#date(2024, 3, 15), Day.Monday)}}
)Date | WeekOfMonth | |
|---|---|---|
| 1 | 3/15/2024 | 3 |
Example 3: Build a weekly period label within the month
Table.AddColumn(
Table.SelectColumns(Table.FirstN(Sales, 5), {"OrderID", "OrderDate"}),
"WeekLabel",
each
Text.From(Date.Year([OrderDate])) & "-"
& Date.ToText([OrderDate], [Format="MMM", Culture="en-US"]) & " W"
& Text.From(Date.WeekOfMonth([OrderDate], Day.Sunday)),
type text
)OrderID | OrderDate | WeekLabel | |
|---|---|---|---|
| 1 | 1 | 1/15/2024 | 2024-Jan W3 |
| 2 | 2 | 1/18/2024 | 2024-Jan W3 |
| 3 | 3 | 2/1/2024 | 2024-Feb W1 |
| 4 | 4 | 2/10/2024 | 2024-Feb W2 |
| 5 | 5 | 3/5/2024 | 2024-Mar W1 |