Date.IsInCurrentMonth

D

T

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

In this article, we are going to take a deep dive into the M code behind the Date.IsInCurrentMonth function. We will also explore some examples of how to use this function in Power Query.

Understanding the M Code

The M code behind the Date.IsInCurrentMonth function is relatively simple. It consists of a single line of code that checks whether a given date falls within the current month.

Here’s the M code for the Date.IsInCurrentMonth function:


(Date) => Date.IsInCurrentMonth(Date)


Let's break down this code line by line.

The first line of code `(Date) =>` is the argument that the function takes. This argument specifies the date that we want to check.

The second line of code `Date.IsInCurrentMonth(Date)` is the code that checks whether the given date falls within the current month. If the given date is in the current month, the function returns `true`. If not, it returns `false`.

Examples of Using the Date.IsInCurrentMonth Function

Now that we understand the M code behind the Date.IsInCurrentMonth function, let's take a look at some examples of how to use this function.

Example 1: Finding Rows with Dates in Current Month

Suppose you have a table that contains a column of dates. You want to filter out all rows that do not have dates in the current month. Here's how you can achieve that using the Date.IsInCurrentMonth function.

1. Select the column of dates that you want to filter.

2. Click on the `Add Column` tab in the Power Query editor.

3. Click on `Custom Column`.

4. In the `Custom Column` dialog box, enter a name for the new column, e.g., "IsInCurrentMonth".

5. In the `Custom Column` dialog box, enter the following formula: `Date.IsInCurrentMonth([Date])`

6. Click `OK` to create the new column.

Now, you will have a new column named "IsInCurrentMonth" that contains `true` or `false` values based on whether the corresponding date falls within the current month or not.

Example 2: Filtering Rows with Dates in Current Month

Suppose you have a table that contains a column of dates. You want to filter out all rows that do not have dates in the current month. Here's how you can achieve that using the Date.IsInCurrentMonth function.

1. Select the column of dates that you want to filter.

2. Click on the `Add Column` tab in the Power Query editor.

3. Click on `Custom Column`.

4. In the `Custom Column` dialog box, enter a name for the new column, e.g., "IsInCurrentMonth".

5. In the `Custom Column` dialog box, enter the following formula: `Date.IsInCurrentMonth([Date])`

6. Click `OK` to create the new column.

7. Click on the `Filter` button in the `IsInCurrentMonth` column.

8. Select `True` from the filter options.

Now, you will have a filtered table that contains only rows with dates in the current month.

In conclusion, the Date.IsInCurrentMonth function is a powerful tool that can help you filter and transform data in Power Query. By understanding the M code behind this function, you can create more complex transformations and filters based on date values.

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

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)