Date.IsInCurrentWeek is a Power Query M function that indicates whether the given date(time) value occurs during the current 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.IsInCurrentWeek( dateTime as any ) as nullable logical
Description
Date.IsInCurrentWeek determines if a given value (of type date, datetime, or datetimezone) falls within the current week as per the system’s date and time.
Examples
Let’s explore two straightforward examples to understand how the Date.IsInCurrentWeek function works.
Identifying Dates in the Current Week
Imagine you have a calendar table and you want to add a column that shows true
for dates that are in the current week. You can do this using the Date.IsInCurrentWeek
function on your [Date]
column.
Date.IsInCurrentWeek( [Date] ) // Output depends on [Date] column
This expression will return true
for any date in the [Date]
column that is part of the current week.
For example, if today is Saturday, July 6 2024, this function will return true
for all rows with dates between Monday, July 1, 2024, and Sunday, July 7, 2024. Here’s a screenshot taken during that week:
You can see that dates within the current week of July 2024 are marked with true
.
Using the Current Date and Time
To test if the current date and time fall within the current week, you can use Date.IsInCurrentWeek
along with DateTime.FixedLocalNow. This function checks if the current date and time are in the current week:
// Output: true
Date.IsInCurrentWeek( DateTime.FixedLocalNow() )
In this example, DateTime.FixedLocalNow()
gets the current date and time. The Date.IsInCurrentWeek
function then checks if this date and time are within the current week. This will always be true if today’s date is within the current week.
Related functions
Other functions related to Date.IsInCurrentWeek are:
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy