Power Query Date.EndOfMonth: How to Use It
In this article
Date.EndOfMonth returns the last day of the month for a given date value in Power Query. You give it a date, it gives back the date of that month's final day. It is a built-in function, so nothing needs to be installed or enabled first, but you do need to be working inside the Power Query Editor (or writing an M query that runs in Power Query) and you need a column or value that is already a date, not text.
What You'll Need
- Power Query Editor open in Excel, Power BI Desktop, or another Microsoft tool that hosts Power Query. The function is part of the core M library, so it is available anywhere Power Query runs.
- A date column or a date value to work with. If your column is currently text or a number, you will need to change its type to Date first.
- Basic familiarity with adding a custom column or editing the formula bar. No add-ins or external downloads are required.
Step-by-Step
- Load your data into Power Query. In Excel, select your table and use Data > From Table/Range. In Power BI Desktop, use Home > Transform data to open the Power Query Editor. Menu labels can differ slightly by version, device, or region, but the core commands are the same.
- Confirm the column is a date type. Find the column containing your dates. Its header should show a calendar icon or a date type label. If it shows ABC (text) or 123 (whole number), click the type icon in the column header and choose Date. If the values do not convert cleanly, use Transform > Data Type > Using Locale and pick the correct date format for your source.
- Add a custom column. Go to Add Column > Custom Column. In the dialog, give the new column a name such as Month End. In the formula box, type the function with your column name in square brackets. For a column called OrderDate, the formula is:
Date.EndOfMonth([OrderDate])
Brackets and capitalization matter in M: the column reference must be in square brackets and the function name uses exact casing. - Check the preview. The dialog shows a preview of the result. Each row should show the last calendar day of the month for that row's date. For example, 2024-02-10 becomes 2024-02-29 in a leap year, and 2024-04-15 becomes 2024-04-30. If the preview shows errors, the input column is not a valid date; close the dialog and fix the type first.
- Click OK to create the column. Power Query adds a step to the Applied Steps list. The new column is a date value, so you can use it for filtering, grouping, or joining.
- Set the new column's type if needed. Custom columns usually come through as Any. Click the type icon on the new column header and choose Date so later steps treat it correctly.
- Use it inline instead of a custom column when you only need a filter. You can call the function directly in other places. To keep only rows from the last day of their month, use a filter step with a condition such as
Date.EndOfMonth([OrderDate]) = [OrderDate]. To build a month label, combine it with Date.ToText, for exampleDate.ToText(Date.EndOfMonth([OrderDate]), "yyyy-MM"). - Apply and close. When the query looks right, use Home > Close & Load (Excel) or Home > Close & Apply (Power BI) to send the result back to your workbook or model.
Common Mistakes
- Passing text instead of a date. Date.EndOfMonth expects a date value. A text column like "2024-04-15" will produce an error until you change its type. Convert first, then call the function.
- Forgetting the square brackets. Writing
Date.EndOfMonth(OrderDate)instead ofDate.EndOfMonth([OrderDate])causes an error because M treats the bare name as an unknown identifier. - Wrong capitalization. M is case-sensitive.
date.endofmonthwill not resolve. Use the exact spelling shown in the function documentation. - Expecting a text result. The function returns a date, not a string like "April 30". If you need text, wrap it in Date.ToText with a format string.
- Assuming it handles nulls silently. If the input is null, the result is null. That is usually fine, but it can surprise you in filters where nulls drop out.
- Using it on a datetime column without converting. A datetime value may work in some contexts, but converting to Date first keeps behavior predictable and avoids time-of-day side effects.
Tips
- Pair Date.EndOfMonth with Date.StartOfMonth to build period boundaries for reporting. Start gives the first day, End gives the last day of the same month.
- To get the end of the previous month, subtract a day from the start of the current month:
Date.AddDays(Date.StartOfMonth([OrderDate]), -1). This avoids month-length edge cases. - For quarter-end dates, use Date.EndOfQuarter; for year-end, use Date.EndOfYear. They follow the same pattern and accept the same date input.
- Name custom columns clearly, such as OrderMonthEnd, so downstream steps and report visuals are easy to read.
- If you need the month number or name, use Date.Month or Date.MonthName on the original date rather than parsing the end-of-month result.
- Keep a sample row with a leap-year February date in your test data so you can confirm the function returns the 29th correctly.
Troubleshooting
If the custom column shows Error in every row, the input column is almost certainly not a date type. Close the dialog, select the source column, and change its type to Date. If only some rows error, those rows contain values that cannot be parsed as dates; filter them out or correct them at the source.
If the formula bar shows a syntax error, check three things in order: the function name is spelled and capitalized exactly, the column reference is inside square brackets, and the parentheses are balanced. A missing closing parenthesis is the most common cause.
If the result looks like a number such as 45382 instead of a date, the column type is set to Whole Number. Change the type to Date and the display will correct itself.
If the step works in the editor but the loaded table shows different values, check that no later step changes the column type or replaces values. Steps run in order, so a type change after your custom column can alter the output.
If you cannot find Add Column > Custom Column, make sure you are in the Power Query Editor and not the regular worksheet or report view. The command only exists inside the editor.
Frequently Asked Questions
Does Date.EndOfMonth work in Excel Power Query and Power BI?
Yes. It is part of the standard M library used by both, so the same formula works in either host.
What does it return for February in a leap year?
It returns February 29. The function accounts for the actual number of days in the month and year you pass in.
Can I use it on a column that contains nulls?
Yes, but rows with null input return null. Filter or replace nulls first if you need a value in every row.
How do I get the end of the previous month instead?
Use Date.AddDays(Date.StartOfMonth([YourDate]), -1). That returns the day before the first of the current month, which is the last day of the previous month.
Why does my result show a number instead of a date?
The column type is set to a number type. Change it to Date in the column header or with Transform > Data Type.
Is there a Date.EndOfWeek function?
Yes, Date.EndOfWeek exists and takes an optional argument for the first day of the week. Date.EndOfMonth takes only the date value.