Power Query has no single DateDiff function like DAX does. Instead you calculate the difference between two dates by subtracting one date from another (which returns a duration) and then extracting the part you want with Duration.Days, Duration.TotalDays, Duration.Hours, and similar functions. The shortest working pattern is: add a custom column with a formula such as Duration.Days([End Date] - [Start Date]), then change the column type to Whole Number. This guide walks through doing that in the Power Query Editor, plus the variants for months, years, and working days.

What You'll Need

  • A table already loaded into Power Query (from Excel, a CSV, a database, or another source).
  • Two columns that are recognised as Date or Date/Time type. If they are Text, change the type first or the subtraction will fail.
  • Access to the Power Query Editor: in Excel, use Data > Get Data > Launch Power Query Editor (or edit an existing query); in Power BI Desktop, use Home > Transform data.
  • No add-ins or extra installs. Everything below uses built-in functions.

Menu labels can differ slightly by version, device, and region, so if a button is named a little differently, look for the closest match.

Step-by-Step

  1. Open the Power Query Editor. In Excel: Data > Get Data > Launch Power Query Editor. In Power BI Desktop: Home > Transform data. Select the query that holds your two date columns.
  2. Confirm the data types. Click the type icon in the column header of each date column and set it to Date or Date/Time. Text dates will not subtract correctly. If a column shows errors after changing the type, the source values are not in a format Power Query can read; fix them at the source or use a locale-aware type change.
  3. Add a custom column. On the Add Column tab, click Custom Column. Give it a name such as Days Difference.
  4. Enter the formula. In the formula box, type Duration.Days([End Date] - [Start Date]), replacing the bracketed names with your actual column names. Click OK. This returns a whole number of full days between the two dates.
  5. Check the result type. The new column usually comes in as a number already, but if the type icon shows ABC or Any, click it and choose Whole Number so it sorts and aggregates correctly.
  6. Handle blanks and errors. If either date is null, the result is null; if a value is not a valid date, you get an error. To keep errors out of your model, wrap the formula: try Duration.Days([End Date] - [Start Date]) otherwise null. This returns null instead of an error row.
  7. Use TotalDays if you need fractions. Duration.TotalDays([End Date] - [Start Date]) keeps the decimal part, which matters when the columns are Date/Time rather than Date. Duration.Days drops the fractional day.
  8. Calculate months or years. There is no built-in month-difference function, so use a formula that counts complete months: Date.Year([End Date]) * 12 + Date.Month([End Date]) - (Date.Year([Start Date]) * 12 + Date.Month([Start Date])). For whole years, use Date.Year([End Date]) - Date.Year([Start Date]), then adjust by one if the end date falls before the start date's month and day in the final year.
  9. Count working days (optional). Power Query has no NETWORKDAYS equivalent. The practical approach is to generate a list of dates between the two using List.Dates, filter out Saturdays and Sundays with Date.DayOfWeek, and count the remainder. This is more work than a single formula, so only build it if weekday counts are genuinely required.
  10. Apply and load. Click Close & Load (Excel) or Close & Apply (Power BI) to bring the new column back to your worksheet or model.

Common Mistakes

  • Subtracting text columns. If either column is typed as Text, the subtraction throws an error. Always set the date type first.
  • Confusing Days with TotalDays. Duration.Days returns whole days and ignores the time portion; Duration.TotalDays keeps the fraction. Mixing them up gives off-by-one results around midnight.
  • Expecting a DateDiff function. Power Query does not have one. Searching for it in the formula bar leads nowhere; the duration approach is the correct method.
  • Ignoring nulls. A blank date produces a blank result, which can silently skew averages. Decide whether blanks should be zero, null, or excluded.
  • Assuming month subtraction is exact. Subtracting months by number gives calendar months, not elapsed 30-day periods. State which definition your report uses.
  • Forgetting locale. Dates like 03/04/2025 are ambiguous. If the source is text, set the correct locale when changing the type, or values will swap day and month.

Tips

  • Name your columns without spaces where possible, or accept the bracketed names Power Query inserts; both work, but consistent naming makes formulas easier to read.
  • Use try ... otherwise around any date arithmetic that feeds a report. It keeps one bad row from breaking the refresh.
  • For age calculations, compare against DateTime.LocalNow() or Date.From(DateTime.LocalNow()) rather than a hard-coded date, so the column updates on each refresh.
  • Keep the raw subtraction as a separate step if you may need hours or minutes later; you can branch from the same duration column.
  • Document the definition of "month" and "year" in the query name or a comment, because different teams interpret them differently.

Troubleshooting

The formula returns an error on every row. Check both columns' data types first. If they are Date/Time, subtraction still works; if they are Text, it does not. Change the type, then re-enter the formula.

The result is negative. The end date is earlier than the start date. Either swap the columns in the formula or filter out rows where the end precedes the start.

The result is off by one. You are probably mixing Duration.Days and Duration.TotalDays, or one column includes a time component that pushes the value past midnight. Convert both to Date type with Date.From before subtracting.

The column will not aggregate in a PivotTable or visual. Its type is likely Any or Text. Set it to Whole Number.

Refresh fails after the source changes. A new column name or a changed type in the source breaks the formula references. Open the Applied Steps, find the custom column step, and update the bracketed names.

Dates are swapped day and month. This is a locale issue. Re-do the type change with the correct locale, or fix the source export format.

Frequently Asked Questions

Is there a DATEDIFF function in Power Query?

No. Power Query uses duration arithmetic: subtract the dates, then wrap the result in Duration.Days or Duration.TotalDays. DAX has DATEDIFF, but that is a different language used in the data model, not in the query editor.

How do I get the difference in months?

Use the year-and-month arithmetic shown in step 8. It counts calendar months, which is the usual business definition. There is no built-in month duration function.

Why does my result show decimals?

You are using Duration.TotalDays on Date/Time columns. Switch to Duration.Days for a whole number, or change the column type to Date first.

Can I calculate working days between two dates?

Not with one function. Generate the date list with List.Dates, filter out weekend days using Date.DayOfWeek, and count the remaining rows. Public holidays need a separate reference table.

What happens if one date is blank?

The result is null. Wrap the formula in try ... otherwise null to keep errors out, and decide in your report whether nulls should be treated as zero.

Does this work the same in Excel and Power BI?

Yes. Both use the same Power Query engine and the same functions; only the menu path to open the editor differs.