Date.IsInPreviousNQuarters is a Power Query M function that indicates whether the given date(time) value occurs during the previous number of quarters, as determined by the system. The function returns a boolean value (true or false).
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Date.IsInPreviousNQuarters(
dateTime as any,
quarters as number,
) as nullable logical
Description
Date.IsInPreviousNQuarters determines if a given value (of type date, datetime, or datetimezone) is within a specified number of quarters before the current system date and time, excluding the current quarter. It requires a quarters
argument.
Examples
Let’s explore two straightforward examples to understand how the Date.IsInPreviousNQuarters function works.
Identifying Dates in the Previous N Quarters
Imagine you have a calendar table and you want to add a column that shows true
for dates within the last n quarters. You can do this by using the Date.IsInPreviousNQuarters function on your [Date]
column, where n is the number of quarters you want to check.
Date.IsInPreviousNQuarters( [Date], n ) // Output depends on [Date] column and n
This expression returns true
for any date in the [Date]
column that falls within the previous n quarters. Let’s say you want to check if your dates are in the last 2 quarters. To do that you can use the expression:
Date.IsInPreviousNQuarters( [Date], 2 )
If today is July 6, 2024, this function will return true
for all rows with dates between January 1, 2024, and June 30, 2024. Here’s a screenshot showing this:
You can see that dates within the previous 2 quarters are marked with true
.
Using the Current Date and Time
If we retrieve the current date (generated by DateTime.FixedLocalNow) and shift it back 2 quarters, we can check if it falls within the last three quarters by using:
// Output: true
Date.IsInPreviousNQuarters( Date.AddQuarters( DateTime.FixedLocalNow(), -2 ), 3 )
Related functions
Other functions related to Date.IsInPreviousNQuarters are:
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy