Power Query Date.EndOfQuarter: How to Use It
In this article
Date.EndOfQuarter is a Power Query M function that returns the last day of the quarter containing a given date. It takes a date, datetime, or datetimezone value and returns the same type set to the final day of that quarter. For example, Date.EndOfQuarter(#date(2024, 5, 15)) returns 30 June 2024. You can also add an optional second argument to shift the result by a number of quarters, such as Date.EndOfQuarter(#date(2024, 5, 15), 1) which returns 30 September 2024. No special setup is required beyond access to Power Query, which is built into Excel, Power BI, and other Microsoft data tools.
What You'll Need
- Power Query available in Excel (Data > Get & Transform Data), Power BI Desktop, or another Microsoft tool that hosts Power Query.
- A table or query with a column that contains date, datetime, or datetimezone values.
- Basic familiarity with adding a custom column or editing an existing query step.
Step-by-Step
- Open the Power Query Editor. In Excel, select your data and go to Data > Get & Transform Data > From Table/Range. In Power BI Desktop, use Home > Transform data. The exact menu labels can differ slightly by version, device, or region, but the path is similar.
- Locate the date column. In the Queries pane, select the query that contains your date column. If the column is not already typed as Date, DateTime, or DateTimeZone, change its data type: click the data type icon in the column header and choose Date, Date/Time, or Date/Time/Timezone. Date.EndOfQuarter requires a date-like type; text values will cause an error.
- Add a custom column. Go to Add Column > Custom Column. In the dialog, give the new column a name, such as "Quarter End".
- Enter the formula. In the formula box, type
Date.EndOfQuarter([YourDateColumn]), replacing[YourDateColumn]with the exact name of your date column. For example, if your column is named "OrderDate", useDate.EndOfQuarter([OrderDate]). Click OK. - Check the result. A new column appears with the last date of the quarter for each row. For 15 May 2024, you should see 30 June 2024. If you see errors, verify the column name and data type.
- Shift by quarters (optional). To get the end of a future or past quarter, add a second argument. For example,
Date.EndOfQuarter([OrderDate], 1)returns the end of the next quarter, andDate.EndOfQuarter([OrderDate], -1)returns the end of the previous quarter. The second argument must be an integer. - Set the data type of the new column. Power Query may infer a type, but you can explicitly set it to Date by clicking the data type icon in the new column header and choosing Date. This ensures consistent formatting and downstream calculations.
- Load the query. When finished, go to Home > Close & Load (Excel) or Home > Close & Apply (Power BI) to bring the results into your worksheet or data model.
Common Mistakes
- Using a text column. Date.EndOfQuarter expects a date, datetime, or datetimezone value. If your column is text, convert it first using the data type menu or a function like Date.FromText.
- Misspelling the column name. The column reference must match exactly, including spaces and capitalization. Use the square brackets and the exact name shown in the header.
- Forgetting the optional argument is quarters, not days. The second argument shifts by quarters, not days or months. Passing 1 moves to the end of the next quarter, not the next day.
- Assuming it works on time zones without care. For datetimezone values, the function returns a datetimezone at the end of the quarter in the same time zone. Be aware of how your source stores time zone offsets.
- Expecting it to handle nulls automatically. If the date column contains nulls, the result will be null. You may need to filter or replace nulls before applying the function.
Tips
- For financial quarters that do not align with calendar quarters, calculate the offset manually or use Date.EndOfQuarter with a shifted date. For example, if your fiscal year starts in April, add three months to the date before calling the function, then subtract three months from the result.
- Combine with Date.StartOfQuarter to get both the start and end of the quarter for reporting periods.
- Test the function on a few sample dates to confirm the quarter boundaries, especially around year-end.
Troubleshooting
- Error: "We cannot convert the value to type Date." The column is likely text or another type. Change the data type to Date, Date/Time, or Date/Time/Timezone before using the function.
- Error: "The field 'YourColumn' of the record wasn't found." The column name in the formula does not match the actual column name. Check for typos or extra spaces.
- Unexpected results for datetimezone values. The function respects the time zone offset in the value. If your source data has inconsistent offsets, consider converting to a standard time zone first.
- Null results. If the original date is null, the function returns null. Filter out nulls or replace them with a default date if needed.
- Function not recognized. Ensure you are using Power Query, not a regular Excel formula. Date.EndOfQuarter is an M function and only works inside the Power Query Editor or in M code.
Frequently Asked Questions
What does Date.EndOfQuarter return for a date that is already the last day of a quarter?
It returns the same date. For example, Date.EndOfQuarter(#date(2024, 6, 30)) returns 30 June 2024.
Can I use Date.EndOfQuarter with a datetime column that includes time?
Yes. The function returns a datetime value set to the last day of the quarter at 12:00:00 AM (midnight). The time portion is set to midnight.
How do I get the end of the previous quarter?
Does Date.EndOfQuarter work in Excel Power Query and Power BI?
Yes, it is part of the standard Power Query M library available in both Excel and Power BI, as well as other Microsoft products that embed Power Query.
What is the difference between Date.EndOfQuarter and Date.EndOfMonth?
Date.EndOfQuarter returns the last day of the quarter (March 31, June 30, September 30, or December 31). Date.EndOfMonth returns the last day of the month. Use Date.EndOfQuarter for quarterly reporting.
Can I use Date.EndOfQuarter on a column with null values?
Yes, but the result for null inputs will be null. You may want to filter or replace nulls before applying the function.