Power Query Date.IsInNextNWeeks Function Guide
In this article
The Date.IsInNextNWeeks function in Power Query checks whether a given date falls within the next N weeks from today (based on the current system date). It returns true or false and is useful for filtering upcoming events, deadlines, or deliveries. You need a date column in your table and basic familiarity with Power Query Editor in Excel or Power BI.
What You'll Need
- Excel (2016 or later) or Power BI Desktop installed
- A table loaded into Power Query with at least one date column
- Basic understanding of adding custom columns in Power Query
Step-by-Step
- Open your Excel workbook or Power BI report, then load your data into Power Query by selecting Data > Get Data > From Other Sources > From Microsoft Query (or simply using Data > Queries & Connections if already loaded).
- In Power Query Editor, locate the table containing your date column. Click on the column header to select it. Ensure the column’s data type is set to Date or DateTime — if not, right-click the column header, choose Change Type, and select the correct type.
- With your date column still selected, go to the Add Column tab on the ribbon.
- Click Custom Column to open the dialog box. This is where you’ll enter the formula using
Date.IsInNextNWeeks. - In the Custom column name field, enter a descriptive name like
InNext2WeeksorIsUpcoming. - In the Custom column formula box, type or paste the following:
Date.IsInNextNWeeks([YourDateColumn], 2). ReplaceYourDateColumnwith the actual name of your column (e.g.,[DueDate]), and adjust the number2to the desired number of weeks (e.g.,4for four weeks). - Click OK. A new column appears with
truefor dates within the next N weeks andfalseotherwise. - To verify the logic, sort or filter the table on the new column to see which rows are marked
true. Compare a few dates manually — for instance, if today is June 10, a date of June 20 withN=2(14 days) should returntrue, while June 25 should returnfalseif the week boundary is strictly counted from today.
Common Mistakes
- Mixing up column names : Using the wrong column name in the formula (e.g., vs [OrderDate] ) causes an error. Always check the exact column name in the Power Query editor — including case sensitivity and spaces.
- Incorrect number format: Supplying a non-integer for N (e.g.,
2.5or"2") results in a type error. N must be a whole number (e.g.,3, not"3"or3.0). - Assuming calendar weeks: The function counts N weeks from today, not from the start of the current week. So if today is Wednesday, it includes the rest of Wednesday through the following Tuesday plus N full weeks — not from Monday to Sunday.
- Ignoring time zones: If your data includes
DateTimevalues, Power Query uses your local system time zone. If your data is stored in UTC and converted elsewhere, the function may misclassify dates near midnight. - Using blank or null dates: Passing a blank or null value into
Date.IsInNextNWeeksreturnsnull, nottrueorfalse. This can break filters later if not handled.
Tips
- Combine with Date.IsInPreviousNWeeks or Date.IsInCurrentWeek using or to build broader date ranges (e.g., ).
- Wrap the function in if ... then ... else to provide custom text labels instead of true / false , like: .
- To avoid issues with blank dates, wrap the formula:
if [YourDateColumn] = null then null else Date.IsInNextNWeeks([YourDateColumn], 2). - Use the Filter Rows command on the new column to isolate only upcoming items — right-click the column > Filter > Filter Rows > check
true. - For dynamic reporting, consider creating a parameter for N (in Power BI: Modeling > New Parameter Table) and reference it in your formula using
NWeeksParameter{0}[Value].
Troubleshooting
If your formula returns an error or unexpected results, follow these checks:
- Restart Power Query: Close and reopen Excel or Power BI Desktop. Sometimes stale sessions cause syntax quirks.
- Check column data type: Right-click the date column > Change Type > ensure it shows Date or DateTime. If it’s Text, convert it first using Transform > Format > Date or
Date.From([YourColumn]). - Verify the function name spelling: Power Query is case-sensitive for function names. Use
Date.IsInNextNWeeksexactly — no capitalization errors likedate.isinnextnweeks. - Test with a known date: Add a temporary custom column with a fixed date:
Date.IsInNextNWeeks(#date(2024, 6, 20), 2). If that returnstruebut your real column doesn’t, the issue is with your data (e.g., time component or time zone). - Inspect the M code: Click View > Advanced Editor. Look for your custom column definition. Ensure the column reference matches your table’s actual column name and that parentheses and commas are correct.
- Check system date: The function uses your computer’s clock. If your system date is wrong (e.g., set to last year), the result will be incorrect. Verify in Windows Settings > Time & Language > Date & Time.
Frequently Asked Questions
Does Date.IsInNextNWeeks include today?
Yes — it counts N weeks starting from today (the current system date), so today through the end of the Nth week is included.
Can I use this in a measure in Power BI?
No — Date.IsInNextNWeeks is a Power Query (M) function and can only be used when transforming data in the Query Editor. In DAX (for measures or calculated columns), use WEEKNUM and TODAY() combinations instead.
What happens if my date column has times (e.g., 11:59 PM)?
The function compares full dates and times. A date like 2024-06-22 23:59:59 is still considered part of June 22, so it will be included if within N weeks. It does not round or truncate times.
How does it handle leap years or varying month lengths?
It counts exactly N × 7 days from today. So two weeks is always 14 days, regardless of month boundaries or leap years.
Is there a limit on how large N can be?
No hard limit is enforced, but very large values (e.g., N=10000) may impact performance when filtering large datasets. For most reporting purposes, values under 52 (one year) are typical.
Can I use this with relative dates like DateTime.LocalNow()?
No — Date.IsInNextNWeeks requires a date value, not a function that returns a date. You must pass a column reference (e.g., [OrderDate]) or a literal like #date(2024, 12, 31).