Dax Function: WEEKNUM
Category: Date and Time Functions
The WEEKNUM function in Power BI is a DAX function used to determine the week number of a given date in a year. The week numbers range from 1 (starting from the first week of the year) to 52 or 53, depending on the calendar system used.
Purpose
To calculate the week number for a specific date.
Type of Calculations
Translates a date into its corresponding week number.
Practical Use Cases
- Grouping and analyzing data by weeks instead of days.
- Building time-based visualizations, such as weekly trends.
- Reporting aligned with business or fiscal calendars.
WEEKNUM(<date>, [return_type])</date>
| Parameter | Type | Description |
|---|---|---|
date | Scalar | The date value or column containing date values. Must be a valid date in Power BI. |
return_type | Optional | Determines the week numbering system to use. Defaults to 1 if not provided. |
How Does WEEKNUM Dax Function Works
The WEEKNUM function assigns each date to a week in the year, starting from week 1. It considers the following:
- Default Behavior: Week 1 begins on January 1 and continues to the next week on Sunday.
- Custom Week Start: The
return_typeparameter allows customization of the week start day:1(default): Week starts on Sunday.2: Week starts on Monday.
This function follows the Gregorian calendar, ensuring compatibility with most global date systems.
What Does It Return?
- Type:
Integer. - Meaning: Returns the week number of the given date based on the selected
return_type.
When Should We Use It?
- Weekly Aggregations: To analyze data grouped by weeks, such as sales or activity metrics.
- Time Comparisons: To compare performance week-over-week.
- Calendar-Based Reporting: To align reporting with ISO week standards or custom week starting days.
Examples
Basic Usage
To calculate the week number for a specific date:
WeekNumExample = WEEKNUM(DATE(2025, 2, 10)) -- Default return type
Output: Returns 7 (7th week of the year, starting from Sunday).
Column Usage:
Add a calculated column to determine the week number for each date in a table:
WeekNumColumn = WEEKNUM(Table[OrderDate], 2) -- Week starts on Monday
Output: Returns week numbers where the week begins on Monday.
Advanced Usage
Combine WEEKNUM with other functions to analyze data for specific weeks:
CurrentWeekSales = CALCULATE(SUM(Sales[Amount]), WEEKNUM(Sales[OrderDate]) = WEEKNUM(TODAY()))
Output: Calculates total sales for the current week.
Tips and Tricks
- Align Return Types with Business Needs: Use
return_type = 2for business reporting that starts on Monday. - Combine with Filters: Use
WEEKNUMwithFILTERto isolate data for specific weeks or date ranges. - Fiscal Week Handling: To align with fiscal weeks, additional logic or custom columns may be needed.
Potential Pitfalls
- Fiscal Week Misalignment: WEEKNUM doesn’t inherently support fiscal calendars; custom logic is required for non-Gregorian week systems.
- Invalid Dates: Ensure the
dateparameter contains valid date values to avoid errors.
Performance Impact of WEEKNUM DAX Function:
- Efficient for small datasets but can affect performance if applied to large tables without filtering.
- Use measures rather than calculated columns for better memory optimization.
Related Functions You Might Need
- DATE: Creates a date value from year, month, and day components.
- YEAR: Extracts the year from a date.
- MONTH: Extracts the month from a date.
- WEEKDAY: Returns the day of the week for a given date.
Want to Learn More?
For more information, check out the official Microsoft documentation for WEEKNUM You can also experiment with this function in your Power BI reports to explore its capabilities.
Unlock the full capabilities of Power BI and elevate your data insights with our specialized consulting services. Whether you need guidance on advanced DAX functions like those highlighted here, support in designing interactive dashboards, or expertise in optimizing data models for enhanced performance, our experienced Power BI consultants are equipped to deliver customized solutions for your business. Explore our Power BI Consulting Services page to discover how we can help your organization make smarter, data-driven decisions.
The WEEKNUM function returns the week number of a given date, ranging from 1 to 52 or 53.
Use WEEKNUM(date, 2) to set Monday as the start of the week.
The function works for calendar weeks. Custom logic is needed for fiscal calendars.
The function defaults to 1, where weeks start on Sunday.
WEEKNUM doesn’t directly support ISO weeks. Additional calculations are needed for ISO-compliant results.