Excel Power Query Week Number: A How-To Guide
In this article
To add a week number in Excel Power Query, use the Date.WeekOfYear function inside a custom column: go to Add Column > Custom Column, name it, and enter Date.WeekOfYear([YourDateColumn]). This returns the ISO week number (1–53) for each date. You can also use Date.WeekOfMonth for a week-of-month count. The exact menu labels may vary slightly by Excel version, but the function names are consistent.
What You'll Need
- Excel 2016 or later (Power Query is built-in as Get & Transform). In Excel 2010/2013, Power Query is a free add-in from Microsoft.
- A table or range of data that includes a date column. Dates must be recognised as Date type, not text.
- Basic familiarity with the Power Query Editor window.
Step-by-Step
- Load your data into Power Query. Select your table, then go to Data > From Table/Range. If your data is external, use Data > Get Data and pick the source. The Power Query Editor opens.
- Confirm the date column is typed as Date. Click the column header icon (left of the name) and choose Date. If it shows Text or Any, change it. A wrong type is the most common reason week-number formulas fail.
- Add a custom column. Go to Add Column > Custom Column. In the dialog, give it a name such as Week Number.
- Enter the formula. In the formula box, type — replace with your actual column name, including brackets. Click OK . A new column appears with numbers 1–53.
- (Optional) Get week-of-month instead. Repeat step 3 with the formula . This returns 1–5 (or 1–6) depending on the month.
- (Optional) Control the first day of the week. Date.WeekOfYear accepts a second argument: . Use Day.Sunday or another day if your business week starts differently. Without it, Power Query uses the default (typically Sunday-based in many locales).
- Check the results. Scroll through the new column. Spot-check a few dates against a calendar. If numbers look wrong (e.g., all 1s or errors), see Troubleshooting.
- Load back to Excel. Go to Home > Close & Load. The query loads to a new worksheet as a table, including your week-number column.
Common Mistakes
- Date column stored as text. If the column type is Text,
Date.WeekOfYearreturns an error. Change the type to Date first (step 2). - Forgetting brackets around the column name. Write , not Date . Without brackets, Power Query treats it as a function or keyword.
- Using Excel's
WEEKNUMsyntax. Power Query uses M language, not Excel worksheet functions.WEEKNUMdoes not exist in Power Query; useDate.WeekOfYear. - Assuming ISO week numbers by default.
Date.WeekOfYeardoes not automatically follow ISO 8601 (Monday start, week 1 contains the first Thursday). If you need strict ISO weeks, you must build a custom calculation or use a calendar table (see Tips). - Editing the wrong step. If you add the custom column then change the date type afterward, the formula may break. Fix the type before adding the column, or edit the type step and refresh.
Tips
- Use a date table for ISO weeks. Create a separate table with every date and its ISO week number (calculated in Excel or another tool), then merge it in Power Query via Home > Merge Queries. This avoids complex M code.
- Name your steps. In the Applied Steps pane, right-click a step and rename it (e.g., "Add Week Number") so the query is easier to audit later.
- Combine year and week. Add another custom column: to get labels like 2024-W05 .
- Refresh behaviour. Week numbers recalculate on refresh. If your source dates change, the week numbers update automatically — no manual editing needed.
- Test with edge dates. Check 1 January and 31 December, since week numbering around year boundaries is where locale differences show up.
Troubleshooting
- Error: "We cannot apply operator & to types Text and Number." Your date column is text. Change its type to Date (step 2), then refresh the custom column step.
- All week numbers are 1 or blank. The column reference is wrong or the date column contains nulls. Check the exact column name in the formula and filter out null dates if needed.
- Numbers don't match Excel's
WEEKNUM. That's expected — Power Query and Excel use different default week rules. Specify the start day inDate.WeekOfYearor use a calendar table for consistency. - Custom Column button greyed out. Make sure you're in the Power Query Editor (not the worksheet) and that a query is selected. Also check the query isn't in a read-only state.
- Formula rejected with "Token Comma expected." You likely missed a closing bracket or used a comma instead of a period in the function name. M uses periods:
Date.WeekOfYear. - If that did not work: delete the custom column step, re-check the date type, and re-add the column. If the query itself is corrupted, start a new query from the same source and rebuild — Power Query steps are quick to recreate.
Frequently Asked Questions
Does Power Query have a built-in week number button?
Not a one-click button for week number specifically. You use Add Column > Custom Column with the Date.WeekOfYear function. The Date menu under Add Column offers year, month, day, and quarter, but week number is done via custom column.
Is Date.WeekOfYear ISO 8601 compliant?
No, not by default. It uses the locale's first-day-of-week setting. For strict ISO weeks (Monday start, week 1 contains the first Thursday), you need a custom calculation or a pre-built calendar table merged into your query.
Can I get the week number as text with a leading zero?
Yes. Wrap the result: . This gives "01" through "53".
Why does my week number differ from Excel's WEEKNUM function?
Excel's WEEKNUM and Power Query's Date.WeekOfYear use different default rules for the first day of the week and the first week of the year. To align them, set the start day explicitly in Power Query, or use a calendar table as the single source of truth.
Do week numbers update when I refresh the query?
Yes. The custom column is recalculated on every refresh based on the current date values in your source. No manual intervention is needed.
Can I use week numbers in a PivotTable?
Yes. After loading the query to a worksheet, the week-number column behaves like any other field. Add it to a PivotTable's Rows or Columns area to group data by week.