Power Query Date.IsInNextNDays Function Guide
In this article
The Date.IsInNextNDays function in Power Query checks whether a given date falls within the next *N* days from today (or from a specified reference date). It returns true or false and is useful for filtering upcoming deadlines, scheduling alerts, or identifying near-term events in your data. You need only a valid date column and optionally a number for *N*—no extra setup is required beyond having Power Query available in Excel (2016+) or Power BI Desktop.
What You'll Need
- Excel 2016 or later (with Power Query enabled by default), or Power BI Desktop
- A table or query containing a date column (e.g.,
DueDate,EventDate) - Basic familiarity with Power Query Editor (adding columns, using formulas)
Step-by-Step
- Open Excel or Power BI Desktop, load your data into Power Query by selecting Data > Get Data > From Other Sources (e.g., Excel table, CSV, database), or use an existing query. Once loaded, click Transform Data to open Power Query Editor.
- In the query containing your date column, locate the column with the date values (e.g.,
DueDate). Ensure the column type is set to Date or DateTime—right-click the column header, choose Change Type, and verify. If it's text, convert it first using Date.From or DateTime.From (e.g.,Date.From([DueDate])). - Click Add Column > Custom Column to open the dialog box.
- Enter a column name like
IsInNext7Daysin the New column name field. - In the Custom column formula box, enter the function. For example, to check if the date is within the next 7 days from today:
Date.IsInNextNDays([DueDate], 7). If you want a dynamic *N* (e.g., from a parameter), replace7with a parameter name (e.g.,N). - Click OK. A new column appears with
trueorfalsevalues. You can now filter this column to show only upcoming dates. - To apply the filter, click the dropdown arrow on the new column header > uncheck
false> click OK. This leaves only rows where the date falls in the next *N* days. - Optionally, right-click the new column and choose Remove Other Columns to keep only essential fields, then click Close & Load to return the filtered table to Excel or Power BI.
Common Mistakes
- Using text instead of date types: If your date column is stored as text (e.g., "2024-06-15"),
Date.IsInNextNDayswill throw an error. Always convert to Date first usingDate.From. - Misunderstanding "next N days" : The function counts *forward from today*, not from the current row’s date. So means "within 5 days from today", not "5 days after this date".
- Passing null or invalid values: If the date column contains blanks or errors, the function returns
null. Handle this withtry ... otherwiseor pre-filter nulls using Filter Rows >[DueDate] <> null. - Time zone mismatches: Power Query uses your system’s local time zone by default. If your data is in UTC or another zone, times may shift. Use
DateTime.FixedLocalNow()consistently or adjust withDateTime.ToLocalif needed. - Forgetting to refresh after changing dates: If you update the current date (e.g., next day), the column won’t auto-update unless you click Refresh in Excel or Apply Changes in Power BI.
Tips
- Use parameters for flexibility: Create a parameter (e.g.,
N) under Manage Parameters > New (type: Whole Number, current value: 7). Then reference it in your formula:Date.IsInNextNDays([DueDate], N). This lets users change the window without editing code. - Combine with conditional logic: To highlight urgency, add another column:
= if [IsInNext7Days] and [Status] = "Open" then "Urgent" else "Normal". - Handle edge cases: For dates in the past, wrap with
Date.IsInNextNDaysandDate.IsInPastto exclude outdated entries:= if Date.IsInPast([DueDate]) then false else Date.IsInNextNDays([DueDate], 7). - Test with sample data: Temporarily add a column like
= Date.AddYears(Date.From(DateTime.LocalNow()), 1)to simulate future dates and verify the function works before filtering. - Consider performance: Avoid using
Date.IsInNextNDaysin large queries with complex transformations—filter early (e.g., first remove nulls, then add the column) to reduce calculation load.
Troubleshooting
If Date.IsInNextNDays isn’t working as expected, follow these steps:
- Check for typos in the function name: Power Query is case-sensitive. Use
Date.IsInNextNDaysexactly (capitalD,I,NinNDays). - Verify the date column type: Hover over the column header in Power Query Editor. If it says
AnyorText, right-click > Change Type > Date. Re-enter your custom column formula after fixing the type. - Test with a hardcoded date: In a new custom column, try:
= Date.IsInNextNDays(#date(2025,1,1), 365). If this returnstrue(assuming today is before Jan 1, 2025), the function works—your issue is likely data quality. - Check for nulls or errors: Add a column with
= Text.From([DueDate])to inspect values. If you see blanks or error messages (e.g.,#ERROR), filter them out first or usetry Date.IsInNextNDays([DueDate], 7) otherwise false. - Confirm system date/time: If your PC/server clock is wrong,
Date.IsInNextNDayswill use the incorrect reference point. Ensure your system time is accurate in Windows/macOS settings. - Restart Power Query Editor: Occasionally, the editor glitches. Close and reopen Excel/Power BI, reload the query, and retry.
- Update Power Query: In Excel, ensure you’re on a supported version (Microsoft 365 subscriptions get updates). In Power BI Desktop, go to File > Options and settings > Options > Current Version to check for updates.
Frequently Asked Questions
Does Date.IsInNextNDays include today?
Yes. The function counts today as day 0. For example, Date.IsInNextNDays(today, 3) returns true for today, tomorrow, the day after, and the third day from now.
Can I use this with a date column from another time zone?
Yes, but you must normalize the time zone first. Convert the column to your local time using DateTime.ToLocal (e.g., Date.IsInNextNDays(DateTime.ToLocal([UtcDate]), 7)) or adjust both the reference and data to UTC using DateTime.From with TimeZoneInfo if needed. Mismatches cause off-by-one-day errors.
What if I need to check the next *N* business days, not calendar days?
Date.IsInNextNDays only handles calendar days. For business days, create a custom column using as a rough approximation, or build a calendar table with weekend flags and filter using Table.SelectRows with Date.DayOfWeek .
Does this work in Power BI DAX or only in Power Query?
Only in Power Query (M language). DAX has no direct equivalent. In DAX, use in a calculated column or measure.
Why does my column show #ERROR instead of true/false?
Most often, this happens when the input is null, text, or a non-date value. Check for blanks with Table.SelectRows, or wrap the formula in try ... otherwise false to suppress errors. Also ensure your data source supports the Date type (e.g., some Excel cells formatted as text won’t auto-convert).
How do I make this dynamic per user (e.g., each user sees only their next 7 days)?
Use parameters or row-level security (RLS) in Power BI. In Power Query, create a parameter (e.g., UserId), join to a user-specific table, and apply filters before adding the date column. In Excel, use a cell reference (via Excel.CurrentWorkbook()) to drive the parameter value.