Date.WeekOfMonth

Date

Returns the week number within the month (1–6) for the given date.

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

Syntax

Date.WeekOfMonth(dateTime as any, optional firstDayOfWeek as nullable number) as nullable number

Parameters

NameTypeRequiredDescription
dateTimeanyYesA date, datetime, or datetimezone value.
firstDayOfWeeknumberNoA Day.* constant specifying the first day of the week. Defaults to Day.Sunday (0). Use Day.Monday (1) for ISO weeks.

Return Value

numberAn 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
)
Result
OrderID
OrderDate
WeekOfMonth
111/15/20243
221/18/20243
332/1/20241
442/10/20242
553/5/20241

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)}}
)
Result
Date
WeekOfMonth
13/15/20243

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
)
Result
OrderID
OrderDate
WeekLabel
111/15/20242024-Jan W3
221/18/20242024-Jan W3
332/1/20242024-Feb W1
442/10/20242024-Feb W2
553/5/20242024-Mar W1

Compatibility

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