Date.Month

Date.Month

D

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

What is the Date.Month Function?

The Date.Month function is a built-in function in Power Query that extracts the month from a date value. The function takes a date value as its input and returns the month as an integer between 1 and 12. For example, if you have a date value of January 1, 2022, the Date.Month function would return 1.

The M Code Behind the Date.Month Function

The Date.Month function is actually a simple piece of M code that you can write yourself. Here is the M code for the Date.Month function:


(Date) => Date.Month(Date)


As you can see, the function takes a date value as its input (which we have named "Date" in this case) and then calls the built-in Date.Month function to extract the month from the date. That's it! With this simple code, you can create your own Date.Month function in Power Query.

Using the Date.Month Function in Power Query

Now that you understand the M code behind the Date.Month function, let's look at how you can use it in your own Power Query projects. Here is an example of how to use the Date.Month function to extract the month from a date column in a table:

1. Open Power Query and load the table that contains the date column.

2. Select the date column and click on the "Add Column" tab.

3. Click on "Custom Column" and enter the following formula:


= Date.Month([Date])


4. Click "OK" to create the new column.

This will create a new column in your table that contains the month value for each date value in the original column.

In conclusion, the Date.Month function is a powerful tool in Power Query that allows you to extract the month from a date value. By understanding the M code behind the function, you can create your own custom functions in Power Query and tailor them to your specific data needs. With this knowledge, you can take your data analysis skills to the next level and become a true Power Query expert.

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)

Copyright, G Com Solutions Ltd, 2024.
Tower Bridge Business Centre, 46-48 East Smithfield, London E1W 1AW
0800 998 9248   |   9:00 a.m. till 5:30 p.m.

Connect With Me: