Power Query Date.IsInNextNMonths Function Guide
In this article
The Date.IsInNextNMonths function in Power Query checks whether a given date falls within the next N months from today’s date (based on the current system time). It returns true or false and is useful for filtering upcoming deadlines, future events, or time-based reporting. You must have Power Query enabled in Excel or Power BI and work with a proper date column to use this function effectively.
What You'll Need
- Microsoft Excel (2016 or later) or Power BI Desktop installed
- A data table containing at least one column with valid date values (e.g., StartDate, DueDate)
- Basic familiarity with Power Query Editor (opening it via Data > Get & Transform Data or Power BI’s Transform Data)
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 any existing query under Get & Transform Data). In Power BI, open Power BI Desktop, load your dataset, then click Transform Data on the Home tab.
- Once in the Power Query Editor, locate the column containing your target dates. Ensure it’s formatted as a Date type. If not, right-click the column header > Change Type > Date (not Date/Time, unless your logic requires time precision).
- Create a new custom column for the condition check. With your table selected, go to the Add Column tab > Custom Column. In the dialog box, name the column something like “IsInNextNMonths”.
- In the Custom column formula box, enter:
Date.IsInNextNMonths([YourDateColumn], N), replacingYourDateColumnwith the actual column name (e.g., [DueDate]) andNwith a whole number (e.g., 3 for the next three months). Example:Date.IsInNextNMonths([DueDate], 3). - Click OK. Power Query evaluates each row: if the date in [DueDate] falls between today and three months from today (inclusive of the first day of the current month up to the last day of the Nth month), it returns true; otherwise, false.
- Optionally, filter the table to show only true rows. Click the filter icon on the new column header, uncheck false, and click OK. This leaves only rows where the date is in the next N months.
- Close & Load to return the filtered table to Excel or Power BI. In Excel, click Close & Load in the Home tab. In Power BI, click Close & Apply.
Common Mistakes
- Using a text-formatted date column instead of a native Date type. This causes the function to fail or return only false. Always verify the column type in Power Query (look for the calendar icon).
- Passing a null or blank value into the function. If your source data has missing dates, add an earlier step to replace nulls (e.g., right-click column > Replace Values > null > today’s date or leave blank and filter later).
- Confusing “next N months” with “next N days.” Date.IsInNextNMonths is strictly month-based and includes the current month. For instance, today is May 15, and you set N = 1: the range covers May 15–31 plus June 1–30.
- Assuming it’s based on a fixed reference date (e.g., report date). It always uses the system’s current date and time when the query refreshes, so results change daily without manual intervention.
- Forgetting to refresh queries after changing N or the source data. Right-click the query in the Queries pane and select Refresh to update results.
Tips
- Combine with other date functions for flexibility. For example, use
Date.IsInNextNMonths([DueDate], 3) and [Status] = "Open"in a conditional column to filter both time and state. - Use the new boolean column for conditional formatting in Excel (Home tab > Conditional Formatting) or Power BI visuals (Format pane > Data colors).
- To exclude the current month, subtract one day from today using
Date.IsInNextNMonths(Date.AddMonths(Date.From(DateTime.FixedLocalNow()), -1), N)—but note this is advanced; test thoroughly. - Save your Excel workbook or Power BI report before refreshing large queries with this function to avoid losing unsaved edits.
- When sharing workbooks, remind users that the function is time-sensitive: results may differ on their machine if their system clock is set incorrectly.
Troubleshooting
If your Date.IsInNextNMonths function isn’t working as expected, follow these checks:
- Verify column type: Select the date column > Home tab > Data Type dropdown > ensure it’s Date (not Text or Any). If it’s Text, convert it: right-click > Change Type > Date.
- Check for nulls: In the date column, scroll for blank cells or null indicators. Use Transform > Clean > Remove Errors or Replace Values to fix before applying the function.
- Test with a known date: Add a sample row with today’s date or tomorrow’s date and see if it returns true. If not, retype the formula manually—copy-paste errors or hidden characters can break it.
- Confirm N is numeric: Ensure N is a whole number, not text (e.g., “3” instead of 3). If N is dynamic, use a parameter: create a new parameter (Home > New Parameter), set type to Whole Number, then reference it in your custom column as
Date.IsInNextNMonths([DueDate], #"N_Parameter"). - Time zone and refresh timing: If results shift unexpectedly, check your system’s date/time settings. Also, refresh the query manually after opening the file to ensure it uses today’s date.
Frequently Asked Questions
Does Date.IsInNextNMonths include the current month?
Yes. It includes the current month and counts forward N months. For example, with N = 2 and today being April 10, it covers April, May, and June.
Can I use Date.IsInNextNMonths with a date column from a different time zone?
No. The function uses your local system time. If your data originates in UTC or another time zone, convert it first using Date.From(DateTime.From([UTCDate], type datetimezone)) and then apply the function.
Why does my formula show a red squiggly line but still run?
Power Query sometimes flags valid syntax as an error in the editor (especially with dynamic parameters). If the query runs and returns correct results, ignore the visual warning. Always test in a small dataset first.
Is there a way to make it relative to a specific date, like a project start date?
Not directly. Date.IsInNextNMonths always anchors to today. To use another anchor (e.g., [StartDate]), create a custom column: Date.IsInNextNMonths(Date.AddMonths([StartDate], 1), N)—this shifts the reference point by one month before checking.
Does this work in Power Query Online (e.g., Excel for the web)?
No. Power Query’s custom column formulas like Date.IsInNextNMonths require the desktop version of Excel or Power BI Desktop. Excel for the web only supports basic query steps and cannot run complex M code.
Can I use this to compare two dates (e.g., is OrderDate in the next 6 months of InvoiceDate)?
No—Date.IsInNextNMonths is designed only for relative comparison to today. For date-to-date comparisons, use Date.IsInNextNMonths([InvoiceDate], N) and [OrderDate] >= [InvoiceDate] and [OrderDate] <= Date.AddMonths([InvoiceDate], N) as separate conditions in a custom column.