Date.IsInPreviousWeek

Updated on

Date.IsInPreviousWeek is a Power Query M function that indicates whether the given date(time) value occurs during the previous week, 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.IsInPreviousWeek( dateTime as any ) as nullable logical

Description

Date.IsInPreviousWeek identifies if a given value (of type date, datetime, or datetimezone) is within the week preceding the current system date and time, not considering the current week’s dates.

Examples

Let’s explore two straightforward examples to understand how the Date.IsInPreviousWeek function works.

Identifying Dates in the Previous Week

Let’s say you have a calendar table and you want to add a column that shows true for dates within the previous week. You can do this by using the Date.IsInPreviousWeek function on your [Date] column.

Date.IsInPreviousWeek( [Date] ) // Output depends on [Date] column

This expression returns true for any date in the [Date] column that falls within the previous week.

If today is July 6, 2024, this function will return true for all rows with dates between June 24, 2024, and June 30, 2024. Here’s a screenshot showing this:

Example of how to use the Date.IsInPreviousWeek function in Power Query M

You can see that dates within the previous week 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 week, we can check if it falls within the previous week by using:

// Output: true 
Date.IsInPreviousWeek( Date.AddWeeks( DateTime.FixedLocalNow(), -1 ) )

Other functions related to Date.IsInPreviousWeek are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/date-isinpreviousweek

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy