Smart Systems for Home

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

Power Query Duration.Days: Convert Durations to Days

· 6 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

Duration.Days takes a single duration value and returns the whole number of days in it as an integer. In Power Query M, a duration is a record with three fields — Days, Hours, Minutes, and Seconds are also possible — and Duration.Days simply pulls out the Days field, ignoring everything smaller than a day. So Duration.Days(#duration(5, 12, 30, 0)) returns 5, not 5.5 and not 6. It is not a rounding function. If you need fractional days you must calculate them yourself, and if you need the difference between two dates the function you want is usually not Duration.Days at all but Date.From or a subtraction that produces a duration first. Understanding that distinction saves most of the debugging people do with this function.

What You'll Need

  • Power BI Desktop, Excel with Power Query, or any tool with the Power Query Editor open.
  • A query that already produces a duration column, or two date/datetime columns you will subtract.
  • Basic comfort with the Advanced Editor or the formula bar, since Duration.Days is not a button on the ribbon.

Step-by-Step

  1. Open the Power Query Editor. In Power BI: Home > Transform data. In Excel: Data > Get Data > Launch Power Query Editor. (Labels differ slightly between versions, so look for the equivalent option.)
  2. Confirm what your column actually is. Click the column header. The type icon at the left of the header shows Date, Date/Time, or Duration. Duration shows as a clock-like icon and values look like 5.12:30:00. If the column is text, Duration.Days will throw an error until you change the type.
  3. Decide whether you have a duration at all. Duration.Days needs a duration input. If you have two dates, subtract one from the other to get a duration: [End Date] - [Start Date]. Power Query returns a duration for date minus date.
  4. Add a custom column. Go to Add Column > Custom Column. Name it something like Days Elapsed.
  5. Enter the formula. Type Duration.Days([Duration]), replacing [Duration] with your real column name. Click OK.
  6. Check the result type. The new column should be Whole Number. If it comes back as Any, set the type explicitly with Transform > Data Type > Whole Number.
  7. Handle negative durations. Subtracting a later date from an earlier one gives a negative duration, and Duration.Days returns a negative integer. If you want an absolute value, wrap it: Number.Abs(Duration.Days([Duration])).
  8. Get fractional days when you need them. Duration.Days alone truncates. For a fractional answer, divide Duration.TotalDays by nothing — just use Duration.TotalDays([Duration]) instead, which keeps the hours and minutes as a decimal.
  9. Use it inline instead of a new column. You can apply it at the step level, for example when filtering: keep rows where Duration.Days([Duration]) >= 7. Duration.Days works in any expression, not only in custom columns.
  10. Apply and close. Home > Close & Apply to load the result into your model or worksheet.

Common Mistakes

The single biggest mistake is expecting rounding. Duration.Days(1.9 days) returns 1. It does not round to 2, and it does not return 1.9. If your numbers look one short, this is why. The second is applying Duration.Days to a date or datetime column directly — it errors because the type does not match. Subtract dates first. Third, people forget that Duration.Days on a negative duration gives a negative number, which then breaks charts and averages in confusing ways. Fourth, some users store dates as text (for example "2024-05-01") and wonder why the subtraction fails; change the type to Date before doing arithmetic. Finally, mixing Duration.Days with Duration.TotalDays is common: Duration.Days is the integer day part, Duration.TotalDays is the full value expressed in days.

Tips

  • Remember the family: Duration.Days, Duration.Hours, Duration.Minutes, Duration.Seconds pull out the integer component of each field; Duration.TotalDays, Duration.TotalHours and so on convert the whole duration to that unit.
  • For business-day counts (working days only), Duration.Days will not help because it counts calendar days. Use a date table and filter to working days, or build the logic in DAX with NETWORKDAYS-style patterns.
  • If you are counting days between two dates and times, Duration.Days ignores the time portion, so 23 hours becomes 0 days. Use Duration.TotalDays and round deliberately if partial days matter.
  • Document the formula in a comment or the column name, because six months later "Days" and "TotalDays" columns look identical but behave differently.
  • Test with a known pair of dates — one day apart, one week apart, and one with a time component — before loading a large query.

Troubleshooting

Error: "We cannot convert the value to Duration." The column is the wrong type. Select it, set the data type to Duration (or Date/Time if you plan to subtract), and refresh the step. If the underlying values are text like 3.04:15:00, Power Query may not auto-detect the duration type, so change the type explicitly.

The custom column shows errors only on some rows. Those rows likely contain nulls or blanks. Wrap the formula in a null check: if [Duration] = null then null else Duration.Days([Duration]).

The number is one less than expected. This is truncation, not a bug. Switch to Duration.TotalDays and round with Number.Round if you want nearest-day behaviour.

The step works but the result is negative. The end date is earlier than the start date for those rows. Check the source data or wrap with Number.Abs.

Adding a column breaks an existing step. Custom columns are positional in the Applied Steps; if you insert one mid-query, later steps may reference the wrong column. Add new columns at the end, or update the affected steps.

If that did not work and you are still stuck, simplify: create a query with two literal values using #duration(2, 0, 0, 0) and apply Duration.Days to it. If that returns 2, the function is fine and the problem is your data types; if it errors, check you are in the right query and that the function name is spelled with capital D and S.

Frequently Asked Questions

What does Duration.Days return for 36 hours?

1. It returns the integer day part and ignores the 12 extra hours. Duration.TotalDays returns 1.5.

Can Duration.Days take a date as input?

No. It needs a duration. Subtract two dates to create one, or use Date.Day for the day-of-month number of a single date.

Is Duration.Days the same as DATEDIFF?

No. DATEDIFF lets you specify units and counts boundaries; Duration.Days only reads the day component of a duration. They can give different answers at day boundaries.

How do I count days excluding weekends?

Duration.Days counts calendar days only. Build working-day logic with a date table or in DAX instead of relying on this function.

Why is my result a whole number when I expected a decimal?

Duration.Days is an integer extractor by design. Use Duration.TotalDays for fractional days.

Does Duration.Days work in DAX?

No, it is a Power Query M function. In DAX the equivalent pattern is subtracting dates and wrapping the result in INT or using DATEDIFF.