Date.WeekOfYear

Date

Returns the week number within the year (1–54) 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.WeekOfYear(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 54 representing the week number within the year.

Remarks

Date.WeekOfYear returns the week number within the calendar year, starting from 1. Week 1 is always the week containing January 1. The optional firstDayOfWeek parameter controls which day starts a new week — default is Day.Sunday (0). Always use the Day.* enum constants rather than integer literals to keep code readable. If the input is null, the function returns null.

Be aware that Date.WeekOfYear uses a simple sequential week-counting rule rather than the ISO 8601 standard. ISO 8601 defines week 1 as the week containing the first Thursday of the year, which means January 1 may fall in week 52 or 53 of the previous year in ISO numbering. If you need true ISO week numbers, you will need a custom calculation using Date.StartOfWeek with Day.Monday.

Date.WeekOfYear is useful for week-over-week trend analysis and for creating weekly grouping keys alongside the year. Combine with Date.Year to build a year-week key such as "2024-W03" for consistent period labeling.

Examples

Example 1: Add week number to Sales table

Table.AddColumn(
    Table.SelectColumns(
        Table.FirstN(Sales, 5),
        {"OrderID", "OrderDate"}
    ),
    "WeekOfYear", each Date.WeekOfYear([OrderDate], Day.Sunday), Int64.Type
)
Result
OrderID
OrderDate
WeekOfYear
111/15/20243
221/18/20243
332/1/20245
442/10/20246
553/5/202410

Example 2: Week of year with Monday start

#table(
    type table [Date = date, WeekOfYear = number],
    {{#date(2024, 3, 15), Date.WeekOfYear(#date(2024, 3, 15), Day.Monday)}}
)
Result
Date
WeekOfYear
13/15/202411

Example 3: Build a year-week period label

Table.AddColumn(
    Table.SelectColumns(Table.FirstN(Sales, 5), {"OrderID", "OrderDate"}),
    "YearWeek",
    each
        Text.From(Date.Year([OrderDate])) & "-W"
        & Text.PadStart(Text.From(Date.WeekOfYear([OrderDate], Day.Sunday)), 2, "0"),
    type text
)
Result
OrderID
OrderDate
YearWeek
111/15/20242024-W03
221/18/20242024-W03
332/1/20242024-W05
442/10/20242024-W06
553/5/20242024-W10

Compatibility

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