Date.IsInPreviousNDays Function in Power Query
The Date.IsInPreviousNDays function indicates whether the given datetime value occurs during the previous number of days, as determined by the current date and time on the system.
Syntax
Date.IsInPreviousNDays(dateTime as any, days as number) as nullable logical
The function has the following parameters:
- dateTime: A
date
,datetime
, ordatetimezone
value to be evaluated. - days: The number of days.
Returns:
- TRUE if dateTime falls within the previous N full days.
- FALSE otherwise.
- This function will return FALSE when passed a value that occurs within the current day.
Example: Let’s assume the current date is 3 April 2025.
Power Query M
let Source = Date.IsInPreviousNDays(#date(2025, 4, 2), 3) in Source
The output of the above code is true.
Note: • The function excludes the current day and only considers full past days.
• Useful for dynamic reports that filter records from recent days