Date.WeekOfMonth Function in Power Query
The Date.WeekOfMonth function in Power Query (M language) returns the week number of the month for a given date value. The first week starts at 1, and the start of the week depends on the optional firstDayOfWeek parameter (default is Sunday).
Syntax
Date.WeekOfMonth( dateTime as any, optional firstDayOfWeek as nullable number ) as nullable number
The function has the following parameters:
- date: A value of type
date
from which you want to find the week number within its month. - optional firstDayOfWeek: A number from
Day.Monday (0)
toDay.Sunday (6)
specifying the first day of the week. If omitted, the default isDay.Sunday (6)
.
Return Value
- Returns a number indicating the week of the month starting from 1.
- Returns null if the input is null.
Key Points
- Week counting starts from the first occurrence of firstDayOfWeek in the month.
- If the date is in the first partial week of the month, it's considered week 1.
Example: Default (week starts Sunday).
Power Query M
let Source = Date.WeekOfMonth(#date(2025, 8, 24)) in Source
The output of the above code is 5.
Example: First day of month.
Power Query M
let Source = Date.WeekOfMonth(#date(2025, 8, 1)) in Source
The output of the above code is 1.