Power Query Date.EndOfDay: Step-by-Step Guide
In this article
Power Query's Date.EndOfDay function returns the last moment of a given date—23:59:59.9999999—as a datetime value. It's useful for building date ranges, filtering records to include an entire day, or creating end-of-day timestamps for reporting. You don't need any special setup beyond a Power Query editor (in Excel or Power BI) and a column or value containing dates.
What You'll Need
- Excel 2016 or later, or Power BI Desktop (the function is available in both).
- A query open in the Power Query Editor (Data > Get & Transform Data in Excel; Transform Data in Power BI).
- A date column or a date value you can reference. The function expects a date, datetime, or datetimezone argument.
Step-by-Step
- Open the Power Query Editor. In Excel, go to the Data tab and click Get & Transform Data > Launch Power Query Editor (or From Table/Range if your data is in a worksheet). In Power BI Desktop, click Transform Data on the Home ribbon. Menu labels can differ slightly by version, device, or region.
- Load or select your date column. If your data is already loaded, find the column that contains dates. If you're starting from a blank query, you can type a date literal like
#date(2025,1,15)in a new step. - Add a custom column (recommended for column output). Go to Add Column > Custom Column. In the formula box, enter a formula such as
Date.EndOfDay([OrderDate])where[OrderDate]is your date column. Give the column a name and click OK. This creates a new column with the end-of-day datetime for each row. - Or use the formula bar for a single value. If you want to test the function, click the fx icon next to the formula bar, or simply type
= Date.EndOfDay(#date(2025,1,15))in the formula bar and press Enter. The result will be#datetime(2025,1,15,23,59,59.9999999). - Convert the result if needed. The function returns a datetime value. If you only need the date part (which is the same as the input date), you can wrap it with
DateTime.Date()or just use the original date. If you need a specific format, use the Transform tab's Data Type options to set it to Date/Time or Date. - Apply and close. Click Close & Load (Excel) or Close & Apply (Power BI) to load the results into your worksheet or data model.
Common Mistakes
- Passing a text value instead of a date. The function requires a date, datetime, or datetimezone. If your column is text, first change its data type to Date using the Transform tab.
- Expecting a date-only result. Date.EndOfDay returns a datetime (with time 23:59:59.9999999). If you need just the date, use
DateTime.Date(Date.EndOfDay([Column]))or simply keep the original date. - Using it on a column with nulls. Null values will return null. Handle them with
if [Column] = null then null else Date.EndOfDay([Column])if needed. - Forgetting about time zones. If your value is datetimezone, the function respects the zone offset. Mixing zones can produce unexpected results; convert to a consistent zone first.
Tips
- Use Date.EndOfDay in combination with Date.StartOfDay to create full-day ranges for filtering: to .
- For date-only end-of-day (i.e., the date itself), you don't need this function—just use the date column. Date.EndOfDay is for when you need the timestamp.
- If you're building a custom column, you can reference other columns directly, e.g.,
Date.EndOfDay([StartDate]). - Remember that the function is case-sensitive:
Date.EndOfDay, notdate.endofday.
Troubleshooting
If you get an error like "We cannot convert the value ... to type Date," check the data type of your column. Change it to Date using the Transform tab. If the function returns null unexpectedly, verify that the input isn't null and that it's a valid date. If the result looks like a number (e.g., 45678.99999), the column's data type may be set to Whole Number or Decimal; change it to Date/Time. If the function isn't recognized, ensure you're using a version of Excel or Power BI that supports it (it's been available since Excel 2016). In rare cases, a locale setting might affect date parsing—ensure your date literals use the correct format (yyyy,mm,dd).
Frequently Asked Questions
What does Date.EndOfDay return exactly?
It returns a datetime value representing 23:59:59.9999999 on the given date. For example, Date.EndOfDay(#date(2025,1,15)) returns #datetime(2025,1,15,23,59,59.9999999).
Can I use Date.EndOfDay on a column with time values?
Yes, if the column is of type datetime, the time portion is ignored and the end of that day is returned. If it's datetimezone, the timezone is preserved.
How do I get just the date from Date.EndOfDay?
Wrap it with DateTime.Date(): DateTime.Date(Date.EndOfDay([Column])). That returns the same date as the input.
Is Date.EndOfDay available in Power Query for Excel 2010 or 2013?
No, it was introduced in Excel 2016. For older versions, you can achieve the same result by adding a time fraction: .
What's the difference between Date.EndOfDay and DateTime.LocalNow?
Date.EndOfDay works on a specific date you provide; DateTime.LocalNow returns the current date and time. They serve different purposes.
Can I use Date.EndOfDay in a calculated column in Power BI?
Yes, but it's a Power Query function, so you'd use it in the Query Editor, not in DAX. In DAX, you'd use DATEVALUE or similar functions.