The M Code Behind the Power Query M function Date.IsInNextMonth

In this article, we will take a closer look at the M code behind the Date.IsInNextMonth function, and explore how this function works.

Understanding the Date.IsInNextMonth Function

The Date.IsInNextMonth function is a Boolean function that returns either true or false, depending on whether a given date falls within the next month. This function takes a single argument, which is the date you want to check.

Here is an example of how you can use the Date.IsInNextMonth function in Power Query:


Source = #table({“Date”},{{#date(2022, 4, 25)}, {#date(2022, 5, 25)}, {#date(2022, 6, 25)}}),

#”Filtered Rows” = Table.SelectRows(Source, each Date.IsInNextMonth([Date]))


#”Filtered Rows”

In this example, we are creating a table with three dates, and then filtering the table to only include dates that fall within the next month. The Date.IsInNextMonth function is used as the filter condition.

Exploring the M Code Behind Date.IsInNextMonth

Now that we understand how the Date.IsInNextMonth function works, let's dive into the M code behind this function.

The M code for the Date.IsInNextMonth function is relatively simple. Here is the code:

(Date) => Date.Month(Date.AddMonths(Date.From(Date),1)) = Date.Month(Date.AddMonths(Date.From(Date.IsDateTime(Date)),1))

Let's break down this code into its individual components:

- `(Date)` is the argument passed to the function. This is the date that we want to check whether it falls within the next month.

- `Date.IsDateTime(Date)` converts the input date to a DateTime value. This is required because the Date.AddMonths function only works with DateTime values.

- `Date.From(Date.IsDateTime(Date))` converts the DateTime value back to a Date value, so that we can extract the month later on.

- `Date.AddMonths(Date.From(Date.IsDateTime(Date)),1)` adds one month to the input date, and returns a new date value.

- `Date.Month(Date.AddMonths(Date.From(Date),1))` extracts the month from the new date value that we just created.

- `Date.Month(Date.AddMonths(Date.From(Date.IsDateTime(Date)),1))` extracts the month from the input date, after adding one month to it.

- The function compares the two extracted months, and returns true if they are equal, and false otherwise.

The Date.IsInNextMonth function is a powerful tool that can help you filter data based on dates in Power Query. Understanding the M code behind this function can help you customize and extend its functionality to suit your specific needs.

We hope that this article has provided you with a deeper understanding of how the Date.IsInNextMonth function works, and how you can use it to improve your Power Query skills.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us


    Your Name (required)


    Email (required)


    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)