How to Use Power Query's Date.IsInNextWeek Function
In this article
The Date.IsInNextWeek function in Power Query checks whether a given date falls within the upcoming calendar week (Monday to Sunday in most locales), returning TRUE or FALSE. It’s useful for filtering upcoming events, planning reports, or flagging near-term deadlines. You must have Power Query enabled in Excel or Power BI, and your date column must be of the correct Date or DateTime type.
What You'll Need
- Excel (2016 or later) or Power BI Desktop (latest version)
- A table with a date column (e.g., 'OrderDate', 'DueDate')
- Basic familiarity with Power Query Editor (opening it, adding custom columns)
Step-by-Step
- Open your Excel workbook or Power BI report and load your data into Power Query. In Excel, go to the Data tab > Get Data > From Other Sources > From Microsoft Query or use the Data Model. In Power BI, click Transform Data in the Home tab.
- Once Power Query Editor opens, locate your table in the Queries pane on the left. Click the dropdown arrow next to your table name and select Edit to open the query editor for that table.
- Ensure your date column is set to the correct data type. Right-click the column header, choose Change Type, and select Date (not Text or DateTime unless you need time precision). If the column shows errors, click the error icon and choose Replace Errors > null to clean it before proceeding.
- Add a custom column to evaluate whether each date is in the next week. Go to the Add Column tab > Custom Column. In the dialog box, enter a name like 'IsNextWeek' in the Column name field.
- In the Custom column formula box, type:
Date.IsInNextWeek([YourDateColumn]). Replace 'YourDateColumn' with the actual column name (e.g., [OrderDate]). Ensure square brackets surround the column name and the function name is spelled exactly as shown. - Click OK. Power Query calculates the result for each row. You’ll see TRUE for dates falling in the upcoming Monday–Sunday week (or Sunday–Saturday depending on locale), FALSE for others, and null if the source date was null or invalid.
- To refine results, you can sort or filter. Click the filter icon on the new column header, uncheck FALSE and null to show only upcoming-week entries, or use the filter to exclude non-matches. To keep the column permanently, click Close & Load to load the table back to Excel or Power BI.
Common Mistakes
- Using the wrong column reference: Forgetting brackets around the column name (e.g., Date.IsInNextWeek(YourDateColumn) instead of [YourDateColumn]) will cause a Formula.Error. Always use brackets.
- Leap-year or timezone confusion: Date.IsInNextWeek calculates weeks based on the system's regional settings. If your system uses Sunday as the start of the week, it may differ from expectations. You can change this in Windows Settings > Time & Language > Region > Regional format.
- Assuming it includes today: The function checks only the *next* calendar week, not the current week or today. If today is Tuesday and you want to include today through Sunday, use Date.IsInCurrentWeek OR Date.IsInNextWeek instead.
- Passing non-date values: If your column contains text like "2024-05-01" instead of a true Date type, the function returns null. Always convert to Date type first.
Tips
- Use conditional formatting in Excel after loading: Select your table, go to Home > Conditional Formatting > New Rule, and apply formatting when the cell value equals TRUE.
- Handle nulls explicitly: Add an IF statement like = if [YourDateColumn] = null then "No Date" else if Date.IsInNextWeek([YourDateColumn]) then "Next Week" else "Other" to improve readability for end users.
- Test with known dates: Enter a test row with tomorrow’s date, next Monday, and a date two weeks away to verify behavior before applying to your full dataset.
- Check your locale in Power Query: Go to File > Options > Current User > Regional Settings. If your locale starts weeks on Sunday, the function aligns with that—adjust expectations accordingly.
Troubleshooting
If Date.IsInNextWeek returns all FALSE or nulls, follow these steps:
- Verify your date column has valid entries: In Power Query, sort the column ascending. If you see errors (e.g., #ERROR, #VALUE), fix or remove them using the replace errors method in Step 3.
- Confirm the column type: Right-click the column > Change Type > Date. If the option is grayed out, the column may be of type Any or Text. Click Transform > Detect Data Type to auto-detect, or manually convert.
- Check for hidden characters: If your date column came from a CSV or web source, extra spaces or non-breaking spaces can prevent recognition. Use the Trim function: = Date.IsInNextWeek(Text.Trim([YourDateColumn])) after converting to text and back to date if needed.
- Test the function manually: In a new custom column, type = Date.IsInNextWeek(#date(2024,6,10)) to see if the function itself works. If it returns FALSE for a known next-week date, your system locale may be misconfigured.
- Restart Power Query or Excel: Sometimes, formula caching causes stale results. Close Power Query, save your workbook, restart Excel, and re-open Power Query to refresh.
Frequently Asked Questions
Does Date.IsInNextWeek work with datetime values?
Yes, it accepts DateTime values and ignores the time portion, treating the entire day as part of the week.
Can I use this to compare two dates, like due date vs. today?
No—Date.IsInNextWeek only compares a single date against the system’s definition of the next calendar week. For relative comparisons (e.g., due date within 7 days), use Date.AddDays(Date.From(DateTime.LocalNow()), 7) and compare directly.
Why does it return null for some rows?
Null means either the input value was null, blank, or could not be converted to a valid date.
Does this function work in Power BI DAX?
No—Date.IsInNextWeek is a Power Query (M language) function, not DAX. In DAX, use ISINSCOPE or CALCULATE with DATEADD for similar logic.
How does it handle leap years or week 53?
It uses the ISO 8601 standard internally for week numbering where applicable, but the function itself is based on calendar weeks (Monday–Sunday or Sunday–Saturday per locale), not ISO week numbers. Leap years do not cause errors.
Can I use this in a custom column that references multiple tables?
No—each custom column operates within a single query’s table. If you need to compare dates across tables, merge queries first (Home > Merge Queries) and then apply the function on the merged result.