Date.IsLeapYear is a Power Query M function that indicates whether the given date(time) value falls in a leap year. The function returns a boolean value (true or false).
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Date.IsLeapYear( dateTime as any ) as nullable logical
Description
Date.IsLeapYear tests if the year of a given value (of type date
, datetime
, or datetimezone
) is a leap year.
Examples
Let’s explore some straightforward examples to understand how the Date.IsLeapYear function works.
Checking Leap Years in a Calendar Table
Imagine you have a calendar table and you want to add a column that shows true
for dates that fall in a leap year. You can do this by using the Date.IsLeapYear function on your [Date]
column as follows:
Date.IsLeapYear( [Date] )
This expression returns true
for any date in the [Date]
column that falls within a leap year.
For instance, in the table below, you can find dates for the first of January for the years 2020 up to 2030. To check which of these years are leap years, you can use the Date.IsLeapYear function on the date column:
By applying the function, dates in the years 2020, 2024, and 2028 are marked as true
because they are leap years.
Checking if the Current Year is a Leap Year
If you want to check if the current year is a leap year, you can use the DateTime.FixedLocalNow function to get the current date and then apply the Date.IsLeapYear function:
Date.IsLeapYear( DateTime.FixedLocalNow() )
The output will depend on the current year when you run the query.
For example, if you run this query on July 7, 2024, it will return true
because 2024 is a leap year:
// Output: true
Date.IsLeapYear( #date( 2024, 07, 07 ) )
These examples show how you can easily identify leap years in your data using the Date.IsLeapYear function in Power Query M.
Related functions
Other functions related to Date.IsLeapYear are:
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy