Power Query Date.IsInPreviousQuarter Function Guide
In this article
The Date.IsInPreviousQuarter function in Power Query checks whether a given date falls within the calendar quarter immediately before the current one — for example, if today is in Q3 2024, this function returns true for any date in Q2 2024 (April–June 2024). It requires a valid date or datetime value and works relative to the system clock at query execution time. No additional setup is needed beyond having a column or expression that evaluates to a date type.
What You'll Need
- A Power Query environment (available in Excel, Power BI Desktop, or Power Automate)
- A column or custom column containing date/datetime values (e.g.,
OrderDate,TransactionDate) - Understanding that the function uses the current system date and time at execution — not a static reference
Step-by-Step
- Open your Power Query Editor (in Excel: Data > Get Data > Edit Queries; in Power BI: Home > Transform Data)
- Select the table containing your date column (e.g., a table named
SalesDatawith a columnOrderDate) - Click Custom Column from the Add Column tab (or right-click the table and choose New Column in Power BI)
- In the formula bar, enter the expression:
Date.IsInPreviousQuarter([OrderDate])— replace[OrderDate]with your actual date column name - Press Enter to apply the column. Power Query will populate a new column of Boolean values (
trueorfalse) indicating whether each row’s date falls in the prior quarter - To filter only previous-quarter rows, click the dropdown arrow on the new column header, uncheck
false, and click OK - Click Close & Apply (Power BI) or Close & Load (Excel) to push the filtered data back to your worksheet or report
Common Mistakes
- Using the wrong column reference — for example, typing
Date.IsInPreviousQuarter(OrderDate)without brackets instead of[OrderDate]. Power Query requires square brackets for column references - Assuming it works with text or numeric date representations — the function expects a true
dateordatetimetype. If your dates are stored as text (e.g., "2024-04-15"), convert them first usingDate.FromorTable.TransformColumns - Forgetting that it’s relative to the *current* system time — if you run the query on April 1, 2024, Q1 2024 (Jan–Mar) is the previous quarter. On July 1, Q2 (Apr–Jun) becomes the previous quarter. It does not support fixed or custom reference dates
- Confusing it with
Date.IsInCurrentQuarterorDate.IsInNextQuarter— double-check the function name spelling to avoid logic errors
Tips
- Combine with
Date.QuarterOfYearto debug: create a helper column showing the quarter number of each date (e.g.,Date.QuarterOfYear([OrderDate])) to verify expected behavior - For dynamic reporting, consider storing today’s date in a separate query (e.g.,
Today = DateTime.LocalNow()) and useDate.IsInPreviousQuarteronly when you truly need *relative* to *now* - If your data spans multiple years, add a year filter first (e.g.,
if [OrderDate] > #datetime(2020,1,1,0,0,0) then Date.IsInPreviousQuarter([OrderDate]) else null) to avoid unexpected results with very old dates - Use
try ... otherwiseto handle nulls safely:try Date.IsInPreviousQuarter([OrderDate]) otherwise false
Troubleshooting
If your Date.IsInPreviousQuarter column returns all false or errors:
- Check data types — right-click the date column header and ensure Data Type is set to
DateorDateTime. If it’sAnyorText, click the type icon and chooseDate - Test with a known date — add a custom column with
= #date(2024, 5, 15)and applyDate.IsInPreviousQuarter. On any date in Q3 2024 or later, this should returntrue— if not, your system clock may be incorrect - Verify your system clock — open
dateandtimesettings on your PC or device. If the year, month, or quarter displayed is wrong, the function will behave incorrectly - Look for hidden time components — if your date includes a time (e.g.,
2024-04-01 14:30),Date.IsInPreviousQuarterstill works correctly. However, ensure your system’s current quarter aligns with your expectations (e.g., Q2 ends June 30) - Check for nulls — if your source data contains blank or null dates, the function returns
null. UseTable.ReplaceNullsor a conditional column to replacenullwithfalsebefore filtering
Frequently Asked Questions
Does Date.IsInPreviousQuarter work with fiscal quarters?
No — it strictly follows the calendar year (Q1: Jan–Mar, Q2: Apr–Jun, Q3: Jul–Sep, Q4: Oct–Dec). For fiscal calendars, use Date.IsInPreviousPeriod with a custom calendar table or calculate quarters manually using Date.QuarterOfYear and Date.Year.
Can I use this function in a calculated column in Power BI?
No —Date.IsInPreviousQuarter is a Power Query (M) function and only runs during data transformation. In DAX (used for calculated columns and measures), use DATEADD and EOMONTH logic instead.
Why does the result change when I refresh the query later?
Because the function compares your dates to the *current* quarter at refresh time. A record dated April 10 will betrue in July, but false in October — when April belongs to the *previous* quarter (Q2), not the *immediately* previous one (Q3).
Does it handle leap years or time zones?
Yes — the function uses the system’s locale and time zone settings to determine the current date. Leap years do not affect quarter boundaries (each quarter spans fixed months), but an incorrect time zone could shift the effective “current date” if near midnight.Can I compare against a specific past quarter (e.g., Q2 2023), not just the prior one?
Not directly —Date.IsInPreviousQuarter only targets the *immediately preceding* quarter. For custom quarters, use a conditional expression like: if [Year] = 2023 and [Quarter] = 2 then true else false, where you derive Year and Quarter columns first.
What happens if I apply this to empty or missing data?
The function returnsnull when the input is null. If your column has no rows, it simply produces no values — no error occurs.