Date.Month Function in Power Query M

Sumit Bansal
Written by

Sumit Bansal is the founder of TrumpExcel.com and a 13-time Microsoft Excel MVP. He started this site in 2013 to share his passion for Excel through easy tutorials, tips, and training videos, helping you master Excel, boost productivity, and maybe even enjoy spreadsheets!

The Date.Month function gives you the month number of a date, from 1 for January to 12 for December. You’d use it to add a month column, filter rows for one month, total values by month, or work out a fiscal month.

In this article, I’ll show you how it works with dates, datetimes, and time zones, and then the most common ways to use it on a table.

Follow along with the example file

Date.Month Function Examples.xlsx

Download

Date.Month Function Syntax

Date.Month(dateTime as any) as nullable number
  • dateTime – the date, datetime, or datetimezone value you want the month number from.

What it returns – the month of dateTime as a whole number from 1 to 12.

If dateTime is null (an empty cell in your data, for example), you get null back instead of an error.

If dateTime is text, like “2026-03-14”, you get an error that says “The Date value must contain the Date component.” You’ll see how to handle text dates in Example 9.

When to Use the Date.Month Function

Use this function when you need to:

  • Get the month number from a date, a date and time, or a date with a time zone
  • Add a month number column to a table
  • Filter rows for one month, whatever the year
  • Total values by month and keep the months in calendar order
  • Work out the fiscal month when your financial year doesn’t start in January
  • Find how many calendar months apart two dates are
  • Get the month from dates that came in as day-first text

Example 1: Get the Month Number From a Date

Let’s start with the simplest use of the function.

Suppose you have the date September 18, 2026, and you want its month number.

Create a new blank query (in Excel, go to Data > Get Data > From Other Sources > Blank Query) and type this formula in the formula bar:

= Date.Month(#date(2026,9,18))

Result: 9

Date.Month(#date(2026,9,18)) returns 9

Here, #date(2026,9,18) creates the date September 18, 2026, and Date.Month returns 9 because September is the ninth month.

The result is a number, not the word “September”. If you want the month name instead, use the Date.MonthName function.

If you want the month of today’s date, give the function today’s date instead of a fixed one. Here’s how to get today’s date in Power Query.

Example 2: Get the Month Number From a Date and Time

Date.Month also works when your value has a time part.

Suppose you have a date and time, March 7, 2026 at 10:45 PM, and you want its month number.

Create a new blank query (as in Example 1) and use this formula:

= Date.Month(#datetime(2026,3,7,22,45,0))

Result: 3

Date.Month(#datetime(2026,3,7,22,45,0)) returns 3, ignoring the time

Here, #datetime(2026,3,7,22,45,0) creates March 7, 2026 at 10:45 PM, and Date.Month returns 3 for March.

Date.Month ignores the time part. So you don’t need to convert a Date/Time column to a Date column before you use Date.Month on it.

Example 3: Get the Month Number From a Date With a Time Zone

Timestamps from web apps and online stores often come with a time zone offset. Here’s what Date.Month does with those.

Suppose an order was placed on December 31, 2026 at 11:30 PM, in a time zone five hours behind UTC (UTC-05:00), and you want its month number.

Create a new blank query (as in Example 1) and use this formula:

= Date.Month(#datetimezone(2026,12,31,23,30,0,-5,0))

Result: 12

Date.Month on a datetimezone value returns 12, the month as written

Here, the last two arguments of #datetimezone, -5 and 0, set the offset to minus five hours and zero minutes. Date.Month returns 12 because it reads the date as it’s written, December 31.

In UTC, that same moment is already 4:30 AM on January 1, 2027. If you need the UTC month, convert the value first with Date.Month(DateTimeZone.ToUtc(...)), which returns 1 here.

Example 4: Add a Month Column to a Table

In real data, you’ll usually want the month number for a whole column of dates.

Below is a SupportTickets table with the date each ticket was opened, and I want the month number of each ticket in a new Month column.

SupportTickets table with Ticket, Agent and Opened On

To follow along, select any cell in the SupportTickets table and go to Data > From Table/Range. In the example file, the Changed Type step sets the Opened On column to the Date type.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","Month",each Date.Month([Opened On]),Int64.Type)

Result: A new Month column shows 1, 2, 2, 5, 8, and 11.

New Month column with the month number of each ticket

Here, the Table.AddColumn function adds the Month column, and the each keyword runs Date.Month on every row. [Opened On] picks the date from the same row.

The last argument, Int64.Type, makes the new column a Whole Number column. Without it, the column type shows as ABC123 (any), and you’d have to set the type in a separate step.

Lillian’s ticket on 2/19/2026 and Evelyn’s ticket on 2/26/2026 both get 2, because they were opened in the same month.

Example 5: Filter Rows for One Month in Any Year

Sometimes you want all the rows for a month, no matter which year they’re in.

Below is a Renewals table with the renewal date of each gym membership across three years, and I want to keep only the members who renew in March.

Renewals table with Member, Plan and Renewal Date across 2025 to 2027

As in Example 4, load the table with Data > From Table/Range.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.SelectRows(#"Changed Type",each Date.Month([Renewal Date]) = 3)

Result: Three rows remain: Patricia (3/12/2025), Vincent (3/27/2026), and Wendy (3/2/2027).

Only the three March renewals remain, one from each year

Here, the Table.SelectRows function keeps only the rows where the condition is true. Date.Month([Renewal Date]) = 3 is true for every March date, whether it’s in 2025, 2026, or 2027.

This is handy for things that repeat every year, like renewals, birthdays, or work anniversaries.

If you want March of one specific year only, add a year check with the Date.Year function. Put and Date.Year([Renewal Date]) = 2026 right after = 3, inside the same formula.

Follow along with the example file

Date.Month Function Examples.xlsx

Download

Example 6: Total Sales by Month in Calendar Order

This next one comes up all the time in monthly reports.

Below is a CateringOrders table with the event date and amount of each catering order, and I want the total amount for each month, with the months in calendar order.

CateringOrders table with Order, Event Date and Amount

As in Example 4, load the table with Data > From Table/Range. In the example file, the Changed Type step sets Event Date to Date and Amount to Decimal Number.

This one takes three steps. Add each as a new step (by clicking on the fx icon next to the formula bar), one after the other.

Each formula starts from the step before it by name.

So rename each new step before you type the next formula, by right-clicking it in Applied Steps and choosing Rename. Name the first one Added Month and the second Grouped Rows.

= Table.AddColumn(#"Changed Type","Month",each Date.Month([Event Date]),Int64.Type)
= Table.Group(#"Added Month",{"Month"},{{"Total Amount",each List.Sum([Amount]),type number}})
= Table.Sort(#"Grouped Rows",{{"Month",Order.Ascending}})

Result: Four rows, one per month: 1 (835), 2 (775), 3 (720), and 4 (930).

Total amount for each month, sorted from January to April

Here, the first step adds a Month column, as in Example 4. The Table.Group function then groups the rows by that column and adds up the Amount values for each month.

For example, the two January orders, 380 and 455, add up to 835. The last step sorts the result by the Month column, so January comes first and April comes last.

This is why the month number is better than the month name for grouping. If you grouped by Date.MonthName instead, sorting would put the months in alphabetical order, so April would come before January.

Important: If your data covers more than one year, grouping by the month number alone puts January 2025 and January 2026 in the same row. So add a Year column with Date.Year and group by both Year and Month.

Example 7: Get the Fiscal Month Number

Many companies don’t start their financial year in January. Here’s how to get the month number within the fiscal year.

Below is an Invoices table with the date of each invoice, and I want the fiscal month number for a financial year that starts in April, in a new Fiscal Month column.

Invoices table with Invoice, Client and Invoice Date

As in Example 4, load the table with Data > From Table/Range.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","Fiscal Month",each Date.Month(Date.AddMonths([Invoice Date],-3)),Int64.Type)

Result: A new Fiscal Month column shows 10, 12, 1, 4, 7, and 9.

New Fiscal Month column for a financial year starting in April

Here, the Date.AddMonths function moves each date back three months, and Date.Month returns the month number of that shifted date. So April becomes month 1, and March becomes month 12.

The invoice on 3/31/2026 gets 12 because it’s the last month of the fiscal year. The invoice on 4/2/2026, just two days later, gets 1 because a new fiscal year has started.

To use a different start month, change -3 to minus the number of months before the start. So use -6 for a July start and -9 for an October start.

Example 8: Find the Month Difference Between Two Dates

Here’s a more advanced one. Sometimes you need to know how many months apart two dates are, counting by calendar month and not by days.

Below is a Milestones table with the planned and actual date of each project milestone, and I want to know how many calendar months late or early each one finished, in a new Month Difference column.

Milestones table with Milestone, Planned Date and Actual Date

As in Example 4, load the table with Data > From Table/Range.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","Month Difference",each (Date.Year([Actual Date])-Date.Year([Planned Date]))*12 + Date.Month([Actual Date])-Date.Month([Planned Date]),Int64.Type)

Result: A new Month Difference column shows 0, 2, 1, -1, and 3.

New Month Difference column: positive for late, negative for early

Here, the formula turns the gap in years into months (by multiplying by 12) and then adds the gap in month numbers. You need the year part because the month numbers alone would give the wrong answer once the dates cross into a new year.

Look at the Roof complete row, planned for 11/25/2026 and finished on 2/12/2027. The month numbers alone give 2 minus 11, which is -9, but adding 12 for the year gap gives the right answer, 3.

A positive number means the milestone finished late, and a negative number means it finished early. Foundation poured was planned for July but done on 6/26/2026, so it shows -1.

The formula only looks at the months, not the days. So the Site survey, planned for 2/15/2026 and done on 2/27/2026, shows 0 because it finished in the planned month.

It also means a short gap can count as a full month. Permits approved was only 13 days late (5/20/2026 to 6/2/2026), but it shows 1 because it crossed into June.

If you need the exact number of days between two dates instead, see how to calculate the date difference in Power Query.

Example 9: Get the Month From Day-First Text Dates

This last one covers a problem you’ll hit when you import data from another country.

Below is a Shipments table exported from a German system, with dispatch dates stored as text in day-first format (day.month.year), and I want the month number of each shipment in a new Month column.

Shipments table with day-first text dates in the Dispatch Date column

If you run Date.Month on this column straight away, every row gives an error, “The Date value must contain the Date component.” That’s because the values are text, not dates.

A plain type change to Date doesn’t fix it on a US computer either. “04.02.2026” quietly becomes April 2, and “23.03.2026” gives the error “We couldn’t parse the input provided as a Date value.”

So first load the table with Data > From Table/Range, as in Example 4. Then delete the automatic Changed Type step (click the X next to it in the Applied Steps pane), because it treats the dates as plain text.

Now change the column type using the right locale. In the Power Query editor, right-click the Dispatch Date header, go to Change Type > Using Locale, pick Date as the data type and German (Germany) as the locale, and click OK.

That creates a step with this formula. If the new step has a different name, right-click it and rename it to Changed Type, because the next formula refers to it by that name.

= Table.TransformColumnTypes(Source,{{"Dispatch Date",type date}},"de-DE")

The “de-DE” at the end tells Power Query to read the text as day, then month, then year. So “04.02.2026” becomes February 4, 2026, not April 2.

Now add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","Month",each Date.Month([Dispatch Date]),Int64.Type)

Result: The Dispatch Date column now shows real dates, and a new Month column shows 2, 3, 5, 6, and 9.

Dispatch Date converted to real dates and a new Month column

Here, Date.Month works because the Changed Type step already turned the text into dates. The first shipment, dispatched on 2/4/2026 (February 4), gets 2, and the second one, on 3/23/2026, gets 3.

The dates show as 2/4/2026 because my computer uses US regional settings. On a computer set to UK settings, the same date shows as 04/02/2026, but the month number is still 2.

Other Excel Articles You May Also Like:

All Power Query Functions

Sumit Bansal

Sumit Bansal

13x Microsoft Excel MVP

Hey! I'm Sumit Bansal, founder of trumpexcel.com and a Microsoft Excel MVP. I started this site in 2013 because I genuinely love Microsoft Excel (yes, really!) and wanted to share that passion through easy Excel tutorials, tips, and Excel training videos. My goal is straightforward: help you master Excel skills so you can work smarter, boost productivity, and maybe even enjoy spreadsheets along the way!

Get the FREE 51 Excel Tips Ebook

Enter your details and the free PDF is on its way to your inbox.

Hmm, that didn't go through. Please check your email and try again.

No spam. You'll also get my weekly Excel newsletter. Unsubscribe anytime.

Check your inbox!

The ebook is on its way to your email. It usually lands within a couple of minutes.