Date.IsInPreviousYear is a Power Query M function that indicates whether the given date(time) value occurs during the previous year, 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.IsInPreviousYear( dateTime as any ) as nullable logical
Description
Date.IsInPreviousYear checks if a given value (of type date
, datetime
, or datetimezone
) falls in the previous year, based on the current system date and time, excluding the current year.
Examples
Let’s explore two straightforward examples to understand how the Date.IsInPreviousYear function works.
Identifying Dates in the Previous Year
Let’s say you have a calendar table and you want to add a column that shows true
for dates within the previous year. You can do this by using the Date.IsInPreviousYear function on your [Date]
column.
Date.IsInPreviousYear( [Date] ) // Output depends on [Date] column
This expression returns true
for any date in the [Date]
column that falls within the previous year.
If today is July 6, 2024, this function will return true
for all rows with dates between January 1, 2023, and December 31, 2023. Here’s a screenshot showing this:
You can see that dates within the previous year are marked with true
.
Using the Current Date and Time
If we retrieve the current date (generated by DateTime.FixedLocalNow) and shift it back one year, we can check if it falls within the previous year by using:
// Output: true for the previous year
Date.IsInPreviousYear( Date.AddYears( DateTime.FixedLocalNow(), -1 ) )
Related functions
Other functions related to Date.IsInPreviousYear are:
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy