Date.EndOfMonth Function (Power Query M)

Date.EndOfMonth returns the last day of the month that contains a given date. Available in Excel (Power Query), Power BI Desktop, and Power BI Service.

If you want the month-end date for any date you have, whether for a billing cutoff, an accounting close, or just the 28th versus the 31st, this is the function to use.

Syntax of Date.EndOfMonth Function

Date.EndOfMonth(dateTime as any) as any

where

  • dateTime (required, any). A date, datetime, or datetimezone value to find the end of the month for.

Returns: the last day of the month that contains dateTime, as the same kind of value you passed in. A date in gives a date out, a datetime in gives a datetime out.

In plain terms, you give it any date in a month and it hands back the final calendar day of that month.

Example 1: Get the last day of the month for a date

Find the month-end date for 12 March 2025.

Date.EndOfMonth(#date(2025,3,12))

Result: 2025-03-31

March has 31 days, so the function returns the 31st. The day part of the input does not matter, only the month and year.

Example 2: February in a leap year

2024 is a leap year, so February has 29 days. Check what the function returns for a February date.

Date.EndOfMonth(#date(2024,2,10))

Result: 2024-02-29

The function works out that 2024 is a leap year and returns the 29th, not the 28th.

Example 3: February in a non-leap year

Now do the same for 2025, which is not a leap year.

Date.EndOfMonth(#date(2025,2,10))

Result: 2025-02-28

February 2025 has only 28 days, so the result is the 28th. You never have to keep track of which years are leap years yourself.

Example 4: Add a billing cutoff column to a table

A common job is turning each customer’s signup date into the last day of that month, so you know when their first billing period ends. From there you can calculate the date difference to find days remaining.

Say you have a Subscriptions query with a Customer and a SignupDate column.

Here is the starting data:

CustomerSignupDate
Acme Co8 Jan 2025
Brightline22 Apr 2025
Coastal LLC11 Feb 2025
Delta Group30 Nov 2025

Type the SignupDate column as a date, then add a BillingCutoff column with Date.EndOfMonth:

let
Source = Excel.CurrentWorkbook(){[Name="Subscriptions"]}[Content],
Typed = Table.TransformColumnTypes(Source,{{"SignupDate", type date}}),
Result = Table.AddColumn(Typed,"BillingCutoff",each Date.EndOfMonth([SignupDate]),type date)
in
Result

The new column holds each row’s month-end date:

CustomerSignupDateBillingCutoff
Acme Co8 Jan 202531 Jan 2025
Brightline22 Apr 202530 Apr 2025
Coastal LLC11 Feb 202528 Feb 2025
Delta Group30 Nov 202530 Nov 2025

Notice the last row. Delta Group signed up on the 30th, which is already the last day of November, so the cutoff stays put.

Things to keep in mind with Date.EndOfMonth

  • The input must be a real date value, not text. Passing a string like "2025-03-12" throws a type error. Columns from Excel.CurrentWorkbook arrive as type any, so type the column first with Table.TransformColumnTypes before calling the function (see Example 4).
  • For a datetime, the time is pushed to the end of the day. The result keeps the date kind but sets the time to 23:59:59.9999999, not the original time. Wrap the call in Date.From for a clean date, or use Date.ToText to format it as a string.
  • It pairs with the other period functions. Date.StartOfMonth gives the first day of the month, Date.EndOfYear the last day of the year, and Date.EndOfQuarter the last day of the quarter.

Common questions about Date.EndOfMonth

How do I get the last day of the month in Power Query?

Use Date.EndOfMonth and pass it any date in that month. It returns the final calendar day, leap years included.

What is the difference between Date.EndOfMonth and Date.DaysInMonth?

Date.EndOfMonth returns a date, the actual last day such as 2025-02-28. Date.DaysInMonth returns just the number of days as an integer, such as 28.

What is the difference between Date.EndOfMonth and Date.StartOfMonth?

Date.EndOfMonth returns the last day of the month, while Date.StartOfMonth returns the first. For a datetime, end-of-month sets the time to 23:59:59.9999999 and start-of-month sets it to 00:00:00.

List of All Power Query Functions

Related Power Query Functions / Articles:

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.