To get the week number in Power Query, select your date column, go to the Add Column tab, select Date > Week > Week of Year. This creates a new column containing the integer representing the week of the year based on the date provided. This process is essential for transforming raw transactional data into time-series reports, allowing you to aggregate sales, website traffic, or production logs by week rather than by individual days.

What You'll Need

  • A dataset imported into Power BI Desktop or Excel Power Query.
  • A column containing dates that is explicitly formatted as a Date or Date/Time data type.
  • Access to the Power Query Editor window.

Step-by-Step

  1. Open the Power Query Editor: In Excel, go to the Data tab and select Get Data > Launch Power Query Editor. In Power BI, click Transform Data from the Home ribbon.
  2. Verify Data Types: Locate the column containing your dates. Look at the icon to the left of the column header. If it shows "ABC" or "123", the week number calculation will not work. Right-click the column header, select Change Type, and choose Date. Note that labels may differ slightly depending on your version of Power BI or Excel.
  3. Access the Date Tools: Click once on the date column to highlight it. Navigate to the Add Column tab on the top ribbon. This ensures you create a new column for the week number rather than overwriting your original date values.
  4. Generate the Week Number: Click the Date dropdown menu. From the resulting list, hover over Week and then click Week of Year. Power Query will automatically generate a new column named "Week of Year" containing numbers from 1 to 53.
  5. Rename the Column: Double-click the header of the new "Week of Year" column and give it a more descriptive name, such as "Fiscal Week" or "Calendar Week", to make your final report easier to read.
  6. Handle Year-Over-Year Data (Optional): If your data spans multiple years, a week number of "1" will appear for both January 2023 and January 2024. To differentiate these, go to Add Column > Date > Year > Year. You can then create a custom column that merges the Year and Week (e.g., "2023-W01") using the Merge Columns feature under the Transform tab.
  7. Apply Changes: Once the column is created and verified, go to the Home tab and click Close & Apply to load the transformed data into your data model.

Common Mistakes

The most frequent error is attempting to calculate the week number on a column that is still formatted as "Text". Power Query cannot perform date math on strings, even if those strings look like dates to the human eye. Always check the data type icon before using the Date tools.

Another common mistake is using the Transform tab instead of the Add Column tab. If you use the Transform tab, Power Query will replace your original date column with the week number. Once the date is gone, you can no longer extract the month, year, or day from that column without undoing the step in the Applied Steps pane.

Users often forget that the default "Week of Year" calculation follows a specific logic (usually starting the week on Sunday). If your organization uses a Monday-start week or a specific ISO 8601 standard, the default button may provide numbers that are off by one. Relying solely on the UI button without verifying the start-of-week logic can lead to reporting discrepancies in financial audits.

Tips

To create a more professional report, use a Custom Column to add a leading zero to single-digit weeks. Instead of "Week 1", you can use a formula like Text.PadStart(Text.From([Week of Year]), 2, "0"). This ensures that when you sort your data alphabetically, Week 02 comes after Week 01, rather than Week 10 coming before Week 2.

If you need to calculate the week number based on a non-standard fiscal calendar (where the year starts in April, for example), avoid the built-in button. Instead, use a Custom Column and subtract the fiscal start date from your current date, then divide by 7 and round up. This gives you total control over the calculation logic.

For large datasets, perform your date transformations as early as possible in the "Applied Steps" list. This helps Power Query optimize the query folding process, potentially pushing the calculation back to the SQL server rather than processing it locally on your machine, which significantly improves refresh speeds.

Troubleshooting

To fix this, right-click the date column and select Remove Errors or Replace Errors with a null value before attempting the week number calculation.

If the week numbers seem incorrect (e.g., January 1st is showing as Week 53 of the previous year), this is usually due to the way Power Query handles partial weeks at the start of the year. To resolve this, you may need to write a custom M-code function using Date.WeekOfYear([DateColumn], Day.Monday) to explicitly define which day the week begins on.

If the "Week of Year" option is greyed out in the ribbon, it is a definitive sign that the selected column is not recognized as a Date type. Check the column header icon again. If it is a "Date/Time/Zone" type, you may need to convert it to a simple "Date" type first using Change Type > Date.

Frequently Asked Questions

Does Power Query use the ISO 8601 standard for week numbers?

The default "Week of Year" button does not strictly follow ISO 8601. ISO 8601 requires that Week 1 is the week containing the first Thursday of the year. The standard Power Query button typically calculates based on the calendar year start. For ISO compliance, you must use a custom M-formula.

Can I change the start day of the week?

You cannot change the start day using the ribbon buttons. However, you can modify the formula in the formula bar. Change Date.WeekOfYear([Column]) to Date.WeekOfYear([Column], Day.Monday) or Day.Saturday to adjust the start day.

How do I handle weeks that overlap two different years?

The best practice is to create a "Year-Week" key. Create a column for the Year and a column for the Week, then merge them with a hyphen. This prevents data from different years from being summed together in your pivot tables or visuals.

Will this work in both Excel and Power BI?

Yes. Power Query is the engine for both applications. The interface, ribbon options, and M-language formulas are identical across both platforms, meaning any week number logic you build in one will work in the other.

What happens to the week number if I change the date?

Because Power Query is a transformation engine, the week number is dynamic. If the source data changes (e.g., a date is updated in your Excel sheet), the week number will automatically update the next time you click Refresh.