Smart Systems for Home

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

Power Query Date.QuarterOfYear: How to Use It

· 6 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.QuarterOfYear returns the quarter number (1 through 4) for a date value in Power Query. You call it as Date.QuarterOfYear(#date(2024, 5, 15)), which returns 2. It works on a single date, not on a column directly, so you use it inside a custom column or a transformation step. This guide walks through adding it to a query, handling errors, and fixing the usual problems.

What You'll Need

  • Power Query available in Excel (Data > Get Data), Power BI Desktop, or Power BI Service (dataflows). The function is the same in all three.
  • A query that already contains a column with date values. If the column is text, convert it to Date first (right-click the column > Change Type > Date).
  • Basic familiarity with the Power Query Editor: the ribbon, the Applied Steps pane, and the formula bar.

Menu labels can differ slightly by version, device, and region. The steps below describe the desktop Power Query Editor, which is where you write custom columns.

Step-by-Step

  1. Open the Power Query Editor. In Excel, select any cell in your table and go to Data > From Table/Range. In Power BI Desktop, use Home > Transform Data. The editor opens with your query loaded.
  2. Confirm the date column is the right type. Click the column header. If the icon shows ABC (text) or 123 (number), right-click the header and choose Change Type > Date. A calendar icon means it is already a date.
  3. Add a custom column. On the Add Column tab, click Custom Column. The Custom Column dialog opens with a name field and a formula box.
  4. Name the new column. Type something like Quarter in the New column name box.
  5. Enter the formula. In the formula box, type:
    Date.QuarterOfYear([OrderDate])
    Replace [OrderDate] with the exact name of your date column. Column names are case-sensitive in M, so match the header exactly.
  6. Check the syntax before committing. The dialog shows a message if the formula is invalid. A green check or no error message means it parsed. Do not click OK yet if you see a red error.
  7. Click OK. Power Query adds a new step to the Applied Steps pane and shows the quarter numbers (1, 2, 3, or 4) in the new column.
  8. Set the column type. The new column may come in as Any. Click the type icon in its header and choose Whole Number so it sorts and aggregates correctly.
  9. Rename if needed and close. Double-click the step name in Applied Steps to give it a clear label, then use Home > Close & Load (Excel) or Home > Close & Apply (Power BI) to load the result.

If you prefer not to write M, there is a no-code route for a related result: select the date column, go to Add Column > Date > Quarter > Quarter of Year. That adds a text label like "Q2" rather than the number 2. Use the custom column method when you need the numeric quarter for sorting or calculations.

Common Mistakes

  • Passing the whole column instead of a row value. Writing Date.QuarterOfYear(OrderDate) without brackets fails. Inside a custom column, always reference the column in square brackets: [OrderDate].
  • Using a text column. If the column is text, the function returns an error. Convert the type to Date first.
  • Wrong column name. M is case-sensitive. [orderdate] will not match a column named OrderDate.
  • Expecting a text label. The function returns a number, not "Q2". If you want the label, wrap it: "Q" & Text.From(Date.QuarterOfYear([OrderDate])).
  • Null dates. If the date cell is blank, the result is null, not an error. Decide whether to filter nulls before or after adding the column.
  • Forgetting the type step. Leaving the new column as Any can break sorting in visuals and in the data model.

Tips

  • To get the quarter start date instead of the number, use Date.StartOfQuarter([OrderDate]). For the quarter end, use Date.EndOfQuarter([OrderDate]).
  • Combine the year and quarter for a sortable label: Date.Year([OrderDate]) * 10 + Date.QuarterOfYear([OrderDate]) gives values like 20242 for Q2 2024.
  • Use the formula bar to edit the step later. Select the step in Applied Steps and change the formula directly instead of deleting and recreating the column.
  • If you need quarters in a fiscal year that does not start in January, the function still returns calendar quarters. Shift the date before calling it, or calculate the fiscal quarter with an offset formula.
  • Test on a small sample first. Filter the query to a few rows, check the output, then remove the filter step.

Troubleshooting

The custom column dialog shows an error. Check three things in order: the column reference uses square brackets and matches the header exactly, the date column is typed as Date, and the function name is spelled Date.QuarterOfYear with the correct capitalization. M function names are case-sensitive.

The column shows Error for some rows. Click the error cell to see the message. A common one is that the value could not be converted to Date, which means those rows contain text or an invalid date. Filter or clean those rows, or add a try expression: try Date.QuarterOfYear([OrderDate]) otherwise null.

The result is null everywhere. The date column is probably empty or the wrong column was referenced. Check the column name and confirm it contains actual date values, not blanks.

The numbers sort as text. Set the column type to Whole Number. If it still misbehaves, check that no earlier step converted the column to text.

The step breaks after a refresh. If the source column was renamed upstream, the formula still points to the old name. Open the step in the formula bar and update the reference. If the source schema changed, re-check the Changed Type step as well.

If that did not work, delete the custom column step, confirm the date column type, and recreate the column. As a last resort, start a new query from the same source and rebuild the steps; this avoids carrying a corrupted step forward.

Frequently Asked Questions

What does Date.QuarterOfYear return for a blank date?

It returns null. It does not throw an error for null input, so blank rows will show as null in the new column.

Does it work on a column of dates directly?

No. It takes a single date value. In a custom column, you pass one row's value at a time using [ColumnName], and Power Query applies it to every row.

Can I get the quarter as text like "Q1"?

Yes. Wrap the result: "Q" & Text.From(Date.QuarterOfYear([OrderDate])). The Add Column > Date > Quarter menu also produces a text label without writing M.

Does it handle fiscal quarters?

No. It always returns calendar quarters based on January to December. For fiscal quarters, shift the date by the offset before calling the function, or calculate the quarter manually.

Is the function the same in Excel and Power BI?

Yes. Both use the same Power Query engine and the same M function. The editor looks slightly different, but the formula and behavior are identical.

What is the difference between Date.QuarterOfYear and the Quarter menu option?

The function returns a number (1 to 4) for calculations and sorting. The menu option adds a text label such as "Q2" for display. Choose based on whether you need a numeric value or a readable label.