Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Date.EndOfYear: Step-by-Step Guide

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Date.EndOfYear is a Power Query M function that returns the last date of the year for any date or datetime value you give it. It is the quickest way to turn a transaction date, a timestamp or a date column into a clean year-end marker, and it needs nothing more than a valid date value and a query where you can add a custom column or edit the M code. The function returns a date (not a datetime) by default, so if you feed it a datetime it drops the time portion and gives you 31 December of that year.

What You'll Need

  • Power BI Desktop, Excel with Power Query (Data > Get & Transform Data), or Analysis Services / Power Query Online where you can edit queries.
  • A table or query that already contains a date column, or a literal date you can type into a formula.
  • Basic familiarity with the Power Query Editor: the Home tab, Add Column tab, and the formula bar.

Menu labels in Power Query can differ slightly by version, host application and region. The steps below describe the Power BI Desktop and Excel Power Query Editor, which share the same layout.

Step-by-Step

  1. Load your data into Power Query. In Excel, select your table and go to Data > From Table/Range. In Power BI Desktop, use Home > Transform data to open the Power Query Editor. Confirm the column you want to work with is typed as Date or Date/Time. You can check the type icon in the column header; if it shows ABC or a number, right-click the header and choose Change Type > Date.
  2. Add a custom column. On the Add Column tab, click Custom Column. In the dialog, give the new column a name such as Year End. In the formula box, type = Date.EndOfYear([OrderDate]), replacing OrderDate with the exact name of your date column (column names are case-sensitive and must be in square brackets). Click OK.
  3. Check the result. The new column should show 31 December of the year in each row. If you see an error instead, the column name is probably wrong or the value is not a date; see Troubleshooting below.
  4. Handle datetime values. If your column is Date/Time, Date.EndOfYear still returns a date, so the time is discarded. If you need a datetime at the end of the year, wrap it: = Date.EndOfYear([OrderDate]) & #time(23,59,59) is not valid M; instead use = DateTime.From(Date.EndOfYear([OrderDate])) and then add the time separately, or simply accept the date result, which is what most year-end reporting needs.
  5. Use it directly in a formula without a custom column. You can also call Date.EndOfYear in the formula bar when editing an existing step, or inside a calculated table expression. For a one-off value, create a blank query (Home > New Source > Blank Query) and in the formula bar type = Date.EndOfYear(#date(2024, 6, 15)), which returns 31 December 2024.
  6. Apply and close. Click Close & Load (Excel) or Close & Apply (Power BI) to push the new column back to your worksheet or data model. The column will be typed as Date; set the format to a short date if it displays as a serial number.

Common Mistakes

  • Forgetting the square brackets. In a custom column, column references must be written as [ColumnName]. Typing OrderDate without brackets produces an error.
  • Using a text column. Date.EndOfYear expects a date, datetime, or datetimezone value. A column stored as text (for example "2024-06-15") returns an error until you change its type to Date.
  • Expecting a datetime back. The function returns a date. If you need a timestamp, convert it explicitly with DateTime.From or combine it with a time value.
  • Case and spacing in column names. [orderdate] is not the same as [OrderDate]. Copy the name from the header to avoid typos.
  • Assuming it handles nulls. A null date returns null, which is usually fine, but if you filter on the result be aware that null rows drop out.

Tips

  • Use Date.EndOfYear together with Date.StartOfYear to build a year bucket: start date in one column, end date in another, then merge or compare.
  • For fiscal years that do not end in December, Date.EndOfYear will not match your fiscal year end. Build the fiscal year end manually, for example by adding months to the start of the fiscal year, or use a date table with a fiscal year column.
  • If you only need the year number, Date.Year is lighter than Date.EndOfYear. Use EndOfYear when you need the actual boundary date for filtering or joining.
  • Keep the original date column. The new column is a derived value and should not replace your source date, which you will still need for sorting and detailed reporting.

Troubleshooting

The custom column shows Error in every row. Click the error link to read the message. The most common cause is a column name mismatch or a column that is still typed as text. Rename the reference or change the type, then refresh the step.

The result is a number like 45657 instead of a date. The column is formatted as a whole number. Select the column, go to the Transform tab, and set the data type to Date. The underlying value is correct; only the display format is wrong.

Some rows are blank. Those source dates are null or empty. Decide whether to filter them out or replace them before applying the function.

The function name is not recognised. Check spelling: it is Date.EndOfYear with capital D, E and Y, and no space. M is case-sensitive for function names.

You cannot find Custom Column. In some hosts the button lives on the Add Column tab rather than the Transform tab. If it is greyed out, make sure a query is selected in the Queries pane and that you are not in the Power Query Editor's diagram view.

Frequently Asked Questions

Does Date.EndOfYear work on a datetime column?

Yes. It accepts date, datetime and datetimezone values and returns a date, so the time portion is dropped.

What date does it return for 29 February 2024?

31 December 2024. Leap days do not affect the result because the function always returns the last day of the calendar year.

Can I use it in a calculated column in DAX?

No. Date.EndOfYear is an M function used in Power Query.

Does it account for fiscal years?

No. It always returns 31 December. For a fiscal year ending in another month, calculate the boundary with Date.AddMonths or a dedicated date table.

Why does my result show a time of 12:00 AM?

It does not; the value is a date. If your tool displays a time, the column has been converted to datetime somewhere in the query. Check the applied steps for a Change Type step.

Is there a StartOfYear equivalent?

Yes. Date.StartOfYear returns 1 January of the same year and takes the same kind of input.