Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Date.IsLeapYear Function: Step-by-Step Guide

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The Date.IsLeapYear function in Power Query checks whether a given date falls in a leap year, returning true if it does and false otherwise. You need only a date value—either a literal, a column, or the result of another function—to use it. This function is built into Power Query and requires no additional setup or dependencies.

What You'll Need

  • A working Power Query environment (available in Excel, Power BI Desktop, or Microsoft Dataverse)
  • A column, table, or expression that provides a valid date value (e.g., #date(2024, 2, 29) or a column named OrderDate)

Step-by-Step

  1. Open Power Query Editor: In Excel, go to the Data tab > Get Data > Launch Power Query Editor (if you're editing an existing query). In Power BI Desktop, go to Home > Edit Queries.
  2. Locate or create a date column: If your query already includes a date column (e.g., OrderDate, BirthDate), skip to step 4. If not, either add a new column via Add Column > Custom Column (see step 3) or load sample data first.
  3. Create a custom column with a date if needed: In the Add Column tab, click Custom Column. In the dialog box, enter a name like TestDate. In the formula bar, type a valid date expression like #date(2024, 3, 15) or #date(2023, 2, 28). Click OK. This gives you a known date to test against.
  4. Add a new column for the leap year check: With your date column ready, go to Add Column > Custom Column. In the Custom column name field, enter something like IsLeapYear.
  5. Enter the Date.IsLeapYear formula: In the Custom column formula box, type Date.IsLeapYear([TestDate]) (replace [TestDate] with the actual name of your date column, including the brackets). For example, if your column is named OrderDate, type Date.IsLeapYear([OrderDate]).
  6. Click OK. Power Query evaluates the function for each row and returns true if the year of the date is a leap year, false otherwise. For instance, Date.IsLeapYear(#date(2024,2,29)) returns true; Date.IsLeapYear(#date(2023,2,28)) returns false.
  7. Review and refine: Hover over the icon next to the new column header to see a sample of values. If all rows show false unexpectedly, double-check that your source column contains valid dates—not text strings masquerading as dates.

Common Mistakes

  • Using text instead of a date type: If your date column is formatted as text (e.g., "2024-02-29"), Date.IsLeapYear will throw an error. Convert the column to Date first using Right-click column header > Change Type > Date.
  • Omitting brackets around the column name: Date.IsLeapYear(TestDate) is invalid. Always use square brackets: Date.IsLeapYear([TestDate]).
  • Passing invalid dates: Date.IsLeapYear(#date(2023,2,29)) will raise an error because February 29 does not exist in 2023. Use only real calendar dates.
  • Confusing leap year logic: Remember, years divisible by 100 are not leap years unless also divisible by 400 (e.g., 1900 is not a leap year, but 2000 is). Date.IsLeapYear handles this automatically, so you don’t need to write conditional logic.

Tips

  • Combine with filtering: After creating the leap year column, click the filter icon > uncheck false to display only leap year dates.
  • Use in conditional logic: Wrap the function in an if expression for custom outputs: .
  • Test edge cases: Try Date.IsLeapYear(#date(2000,1,1)) (returns true) and Date.IsLeapYear(#date(1900,1,1)) (returns false) to verify correct handling of century years.
  • Check for nulls: If your date column may contain nulls, guard against errors: .

Troubleshooting

If Date.IsLeapYear returns an error or unexpected result, follow these checks:

  1. Verify date validity: In Power Query, click the dropdown next to your date column > Filter > Blank to reveal any null or blank entries. Remove or replace them before applying the function.
  2. Check data type: Right-click the column header > Change Type. If Date is not listed or the icon shows text (not a calendar), convert it: select Date. If conversion fails, inspect the source data for inconsistent formats (e.g., 03/01/2024 vs. 01/03/2024).
  3. Review column references: Ensure the column name in the formula exactly matches the actual column name—including spaces and capitalization. Power Query is case-insensitive for column names, but spaces require brackets (e.g., [Order Date]).
  4. Test with a hardcoded date: Create a new custom column with Date.IsLeapYear(#date(2024,1,1)). If this returns true, the issue lies with your source data. If it fails, your Power Query environment may be outdated or corrupted.
  5. Update Power Query: In Excel, ensure you’re running the latest version via File > Account > Update Options > Update Now. In Power BI Desktop, download and install the latest release from the official site.

Frequently Asked Questions

What years does Date.IsLeapYear consider leap years?

It follows the Gregorian calendar rule: a year is a leap year if divisible by 4, except for end-of-century years (e.g., 1900, 2100), which must also be divisible by 400 to qualify (e.g., 2000).

Can Date.IsLeapYear handle null or missing values?

No. Passing null (e.g., Date.IsLeapYear(null) ) returns an error. Always check for nulls first: .

Does this function work in DAX or only Power Query?

Date.IsLeapYear is a Power Query (M language) function only. In DAX (used in Power BI data model), use .

Can I use it with relative dates like Date.From(DateTime.LocalNow())?

Yes. For example, Date.IsLeapYear(Date.From(DateTime.LocalNow())) returns whether the current year is a leap year. This works because Date.From converts the datetime to a date type first.

Why does 2100 return false?

Though divisible by 4, 2100 is divisible by 100 but not by 400, so it is not a leap year under the Gregorian calendar rules that Date.IsLeapYear implements.

How can I list all leap years in a range?

Create a custom table using Table.FromList({2000..2024}, Splitter.SplitByNothing(), {"Year"}), then add a column with Date.IsLeapYear(#date([Year],1,1)), and filter for true.