The Duration.TotalDays function in Power Query gives you the full length of a duration in days, as a decimal number. The hours, minutes, and seconds are counted too, so 3 days and 18 hours comes back as 3.75.
This makes it the function to use when your data has a time along with the date. Below, I’ll go through eight examples, including hospital stays, rental charges, weeks, averages, and durations stored as text.
Follow along with the example file
Duration.TotalDays Function Examples.xlsx
Duration.TotalDays Function Syntax
= Duration.TotalDays(duration as nullable duration) as nullable number
- duration – the duration you want to measure in days. Most of the time, this is one date or datetime subtracted from another, such as
[Discharged]-[Admitted]. It can also be a duration you build with#duration(days,hours,minutes,seconds).
What it returns – a number with the total days in the duration, including the partial day from any hours, minutes, and seconds. If the duration is null, you get null back.
I’ve tested the Duration.TotalDays function in Power Query in Excel for Microsoft 365. It’s also part of the Power Query M language that Power BI uses.
When to Use the Duration.TotalDays Function
Use this function when you need to:
- Get the time between two datetimes as days, with the hours counted as part of a day
- Calculate a length of stay, a turnaround time, or how long something was in transit
- Check whether something took longer than a set number of days
- Charge by the day when items can come back partway through a day
- Convert a duration into weeks, or average durations across a group
- Turn duration text from another system into a number of days
Example 1: Get the Total Days in a Duration
Let’s start with a single duration, so you can see exactly what the function counts.
Say you have a duration of 3 days and 18 hours, and you want it as a number of days. Create a new blank query (Data > Get Data > From Other Sources > Blank Query) and use this formula in the formula bar:
= Duration.TotalDays(#duration(3,18,0,0))
Result: 3.75

Here, #duration(3,18,0,0) creates a duration of 3 days, 18 hours, 0 minutes, and 0 seconds. Since 18 hours is three quarters of a day, Duration.TotalDays returns 3.75.
The Duration.Days function works differently. It returns only the whole days in a duration, so the same duration gives you 3 and the 18 hours are left out.
Example 2: Calculate the Days Between Two Datetimes
This is the most common way you’ll use this function, with a start and an end time in two columns.
Below is an Excel table named PatientStays with the admission and discharge time of each patient, and I want to get each patient’s length of stay in days in a new column.

To follow along, select any cell in the table and go to Data > From Table/Range to open it in the Power Query Editor. If Power Query adds a Changed Type step, use #"Changed Type" in place of Source in the formulas below.
Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.AddColumn(Source,"Length of Stay",each Duration.TotalDays([Discharged]-[Admitted]),type number)
Result: a Length of Stay column with 2.5, 0.75, 4.25, 1.5, 0.5, and 2.75

Here, [Discharged]-[Admitted] subtracts one datetime from the other, which gives a duration. Duration.TotalDays then turns that duration into days, so patient P-502, who was in from 2:00 PM to 8:00 AM the next morning, gets 0.75.
The order of the subtraction matters. If you write [Admitted]-[Discharged] instead, the duration is negative, so a stay of 1.5 days comes back as -1.5.
The Table.AddColumn function adds the new column, and type number sets its data type, so you don’t need a separate step to change the type later.
Example 3: Check If Something Took More Than 2 Days
This is where the difference between the Duration.Days function and Duration.TotalDays changes the answer you get.
Below is an Excel table named Claims with the time each insurance claim was received and approved. The service level agreement (SLA) is to approve every claim within 2 days, and I want a new column that says whether each claim met it.

The Duration.Days function looks like the obvious choice for a check like this, so let’s try it first. Open the table in the Power Query Editor, as in Example 2, and add a new step with this formula:
= Table.AddColumn(Source,"SLA Status",each if Duration.Days([Approved]-[Received])>2 then "Over SLA" else "Within SLA",type text)
Result: only CLM-7106 shows Over SLA. The other five claims show Within SLA.

That’s wrong for two claims. CLM-7102 took 2 days and 6 hours and CLM-7104 took 2 days and 12 hours, but the Duration.Days function drops the hours and sees both as exactly 2 days, and 2 is not more than 2.
Now replace the formula with this one, which uses Duration.TotalDays:
= Table.AddColumn(Source,"SLA Status",each if Duration.TotalDays([Approved]-[Received])>2 then "Over SLA" else "Within SLA",type text)
Result: CLM-7102, CLM-7104, and CLM-7106 show Over SLA. The other three show Within SLA.

Here, Duration.TotalDays returns 2.25 for CLM-7102 and 2.5 for CLM-7104, and both are more than 2. CLM-7105 took exactly 2 days, so it still shows Within SLA.
So when you compare a duration against a limit, use Duration.TotalDays. The Duration.Days function rounds every partial day down, which lets anything less than a full day late slip through.
Example 4: Round the Days to Two Decimal Places
Real timestamps rarely land on the hour, and that gives you long decimals.
Below is an Excel table named TruckTrips with the departure and arrival time of each truck, and I want the days each truck was in transit, rounded to two decimal places, in a new column.

Open the table in the Power Query Editor, as in Example 2, and add a new step with this formula:
= Table.AddColumn(Source,"Days in Transit",each Number.Round(Duration.TotalDays([Arrived]-[Departed]),2),type number)
Result: a Days in Transit column with 1.36, 0.56, 2.85, 1.56, and 3.07

Here, TRK-14 traveled for 1 day, 8 hours, and 35 minutes, which is about 1.3576 days. The Number.Round function rounds that to 1.36, and the 2 in the formula sets the number of decimal places.
Round inside the formula only when you need the rounded number for later steps. If you only want it to look shorter, you can keep the full value and change the number format after you load it to Excel.
Follow along with the example file
Duration.TotalDays Function Examples.xlsx
Example 5: Calculate a Rental Charge for Partial Days
Since Duration.TotalDays counts part of a day, you can multiply it by a daily rate to charge for the exact time.
Below is an Excel table named ToolRentals with each tool’s daily rate and the time it was picked up and returned, and I want the rental charge for each tool in a new column.

Open the table in the Power Query Editor, as in Example 2, and add a new step with this formula:
= Table.AddColumn(Source,"Charge",each Duration.TotalDays([Returned]-[Picked Up])*[Daily Rate],type number)
Result: a Charge column with 67.5, 15, 76, 90, and 175

Here, the Pressure Washer was out for 1.5 days at 45 a day, so the charge is 67.5. The Tile Saw came back after 6 hours, which is 0.25 of a day, so it costs 15 instead of a full day’s 60.
If your rental policy charges a full day for any part of a day, wrap the days in the Number.RoundUp function before you multiply. For example, Number.RoundUp(Duration.TotalDays([Returned]-[Picked Up])) turns 1.5 days into 2.
Example 6: Convert a Duration Into Weeks
Power Query doesn’t have a function that returns the total weeks in a duration, but you can get there from the total days.
Below is an Excel table named ProjectPhases with the start and finish date of each phase of a building project, and I want the length of each phase in weeks in a new column.

Create a blank query (Data > Get Data > From Other Sources > Blank Query). In the Power Query Editor, open the Advanced Editor (Home > Advanced Editor) and use this code.
The Source line reads the table by its name, so if your table has a different name, change ProjectPhases to that name. The same goes for the table names in the later examples.
let
Source = Excel.CurrentWorkbook(){[Name="ProjectPhases"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Start",type date},{"Finish",type date}}),
#"Added Weeks" = Table.AddColumn(#"Changed Type","Weeks",each Duration.TotalDays([Finish]-[Start])/7,type number)
in
#"Added Weeks"
Result: a Weeks column with 2, 3, 4, 1, and 5

Here, the Changed Type step makes Start and Finish date columns. Excel dates come into Power Query with a time of 12:00:00 AM, and this step shows them as plain dates.
Then Duration.TotalDays gets the days in each phase, and dividing by 7 turns them into weeks. Site Prep runs from 3/2/2026 to 3/16/2026, which is 14 days, so it shows 2 weeks.
Since these dates have no time, the days are always whole numbers, and Duration.TotalDays gives the same days as the Duration.Days function. The difference only shows up once there’s a time in the data.
Example 7: Find the Average Turnaround Time by Group
You can also use Duration.TotalDays to get a number for each row first, and then summarize those numbers by group.
Below is an Excel table named LabSamples with the lab that tested each sample and the time it was received and reported. I want the average turnaround in days for each lab, in a new summary table.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="LabSamples"]}[Content],
#"Added Turnaround" = Table.AddColumn(Source,"Turnaround Days",each Duration.TotalDays([Reported]-[Received]),type number),
#"Grouped Rows" = Table.Group(#"Added Turnaround",{"Lab"},{{"Average Days",each List.Average([Turnaround Days]),type number}})
in
#"Grouped Rows"
Result: Chemistry 2, Microbiology 3, and Hematology 1

Here, the Added Turnaround step works out the days for each sample, just like Example 2. The Grouped Rows step uses the Table.Group function to make one row per lab, with the average of that lab’s turnaround days.
Hematology’s three samples took 0.5, 1.5, and 1 day, so its average is 1. You can also build the Grouped Rows step from the ribbon with Home > Group By, using Average as the operation on the Turnaround Days column.
Example 8: Get the Days From Durations Stored as Text
Some systems export durations as text in a days.hours:minutes:seconds format, like 1.06:00:00 for 1 day and 6 hours.
Below is an Excel table named TimeLogs with the time each employee logged on a project, stored as text, and I want the time in days in a new column. Marilyn Adams hasn’t logged any time yet, so that cell is blank.

If you pass this text straight to Duration.TotalDays, every filled row gives an error that says “We cannot convert the value “1.06:00:00″ to type Duration.” The function only accepts a duration, so the text needs to be converted first.
Open the table in the Power Query Editor, as in Example 2, and add a new step with this formula:
= Table.AddColumn(Source,"Days",each Duration.TotalDays(Duration.FromText([Time Logged])),type number)
Result: a Days column with 1.25, 0.75, 2.5, null, 0.25, and 3

Here, the Duration.FromText function reads the text as a duration, and Duration.TotalDays turns it into days. So 1.06:00:00 becomes 1.25, because 6 hours is a quarter of a day.
The blank cell comes into Power Query as null. The Duration.FromText function returns null for it, and Duration.TotalDays passes the null through, so Marilyn Adams gets null instead of an error.
Other Excel Articles You May Also Like:
- Date.AddDays – Use Date.AddDays in Power Query M to add or subtract days from a date.
- DateTime.From – Use DateTime.From in Power Query M to convert values to date and time.
- Date.AddYears – Use Date.AddYears in Power Query M to add or subtract years from a date.
- Date.DayOfWeek – Use Date.DayOfWeek in Power Query M to get the day number of a date.
- DateTime.LocalNow – Use DateTime.LocalNow in Power Query M to get the current date and time.
- Date.EndOfWeek – Use Date.EndOfWeek in Power Query M to get the last day of a week.
- Date.EndOfMonth – Use Date.EndOfMonth in Power Query M to get the last day of a month.
- Date.AddMonths – Use Date.AddMonths in Power Query M to add or subtract months.