Date.IsInPreviousMonth is a Power Query M function that indicates whether the given date(time) value occurs during the previous month, 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.IsInPreviousMonth( dateTime as any ) as nullable logical
Description
Date.IsInPreviousMonth checks if a given value (of type date, datetime, or datetimezone) is in the month prior to the current system date and time, not including the current month.
Examples
Let’s explore two straightforward examples to understand how the Date.IsInPreviousMonth function works.
Checking for Previous Month Dates in a Date Table
Imagine you have a calendar table and you want to add a column that marks dates as true
if they fall in the previous month. You can do this by using the Date.IsInPreviousMonth function on your [Date]
column.
Date.IsInPreviousMonth( [Date] ) // Output depends on [Date] column
This expression returns true
for any date in the [Date]
column that falls in the previous month.
For example, if today is July 7, 2024, this function will return true
for all rows with dates between June 1, 2024, and June 30, 2024. Here’s a screenshot showing this:
You can see that dates from the previous month, June 2024, are marked with true
.
Using the Current Date and Time
To check if a date and time from the previous month falls within the previous month, you can use the following expression:
// Output: true
Date.IsInPreviousMonth( Date.AddMonths( DateTime.FixedLocalNow(), -1 ) )
Related functions
Other functions related to Date.IsInPreviousMonth are:
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy