Smart Systems for Home

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

Power Query Duration.TotalHours: How to Convert Durations

· 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

To convert a duration to total hours in Power Query, use the M function Duration.TotalHours. It takes one duration value and returns a decimal number of hours, so 1 day 12 hours becomes 36, and 90 minutes becomes 1.5. You call it in a custom column, in the formula bar, or inside a step of the Advanced Editor. Nothing needs to be installed first, but the column you feed it must already be a Duration type, not text.

What You'll Need

  • Power Query available in Excel, Power BI Desktop, or another host that runs M queries. The function is part of the standard M library, so no add-in or connector is required.
  • A query with a column that is genuinely of type Duration. If the values are text like "01:30:00" or numbers, you must convert them first, or the function will error.
  • Basic familiarity with the Power Query Editor: the ribbon, the formula bar, and how to add a custom column.

Step-by-Step

  1. Open your query in the Power Query Editor. In Excel, select a cell in your table and go to Data > From Table/Range. In Power BI Desktop, use Home > Transform data. Menu labels can differ slightly by version and host, but the editor layout is the same.
  2. Find the column that holds the duration. Look at the icon in the column header. A clock icon means the column is Duration type. A text icon (ABC) or a number icon (123) means you need to convert it before continuing.
  3. If the column is not Duration, convert it. Select the column, then use Transform > Duration and choose the parse option that matches your data, such as Duration from Text when the values look like "1.02:30:00". If your data is a plain number of minutes, divide by 60 in a custom column instead, because that is not a duration.
  4. Add a new step for the hours value. Go to Add Column > Custom Column. Give it a name such as "Total Hours". In the formula box, type Duration.TotalHours([YourDurationColumn]), replacing YourDurationColumn with the exact name of your duration column. Column names are case-sensitive in M, so match the header exactly.
  5. Click OK. Power Query adds the column and writes a step such as Table.AddColumn(#"Changed Type", "Total Hours", each Duration.TotalHours([Duration])). The result is a decimal number, not a duration.
  6. Check the new column type. Power Query usually infers a number type, but confirm by clicking the icon in the new column header and choosing Decimal Number or Whole Number. If you want whole hours only, wrap the call in Number.RoundDown, for example Number.RoundDown(Duration.TotalHours([Duration])).
  7. Load the result. Use Home > Close & Load (Excel) or Home > Close & Apply (Power BI) to send the table back to your workbook or model.

If you prefer the Advanced Editor, the same logic looks like this inside your query: Table.AddColumn(PreviousStep, "Total Hours", each Duration.TotalHours([Duration])). The function returns a number, so you can use it in later arithmetic, such as multiplying by an hourly rate or summing across rows.

Common Mistakes

  • Feeding text to the function. Duration.TotalHours("01:30:00") fails because the argument must be a duration value, not a string. Convert the column first.
  • Confusing Duration.Hours with Duration.TotalHours. Duration.Hours returns only the hours component of a duration, so 1 day 12 hours gives 12, not 36. Use Duration.TotalHours when you want the whole span in hours.
  • Wrong column name in the formula. M is case-sensitive, so [duration] and [Duration] are different. Copy the name from the header to avoid errors.
  • Expecting a time format. The output is a decimal number. If you need "hh:mm" display, format the result as a number or convert it back to a duration with #duration(0, [Total Hours], 0, 0).
  • Forgetting negative durations. A negative duration returns a negative number of hours, which may break downstream calculations that assume positive values.

Tips

  • Use Duration.TotalMinutes or Duration.TotalDays when hours are not the right unit. The pattern is identical.
  • Round deliberately. Number.Round rounds to nearest, while Number.RoundDown and Number.RoundUp give you control over billing or timesheet rules.
  • Keep the original duration column. It is easy to delete it and later need it for formatting or for a different unit conversion.
  • Name your steps clearly in the Applied Steps pane. A step called "Total Hours" is easier to audit than "Custom Column 1".
  • Test with a known value. A duration of 2.00:00:00 should return 48, and 0.01:30:00 should return 1.5. If not, check the column type.

Troubleshooting

  • Error: "We cannot convert the value to Duration." The column is text or a number. Change the type to Duration, or parse it with the Duration from Text option under Transform > Duration.
  • Error: "The field 'X' of the record wasn't found." The column name in your formula does not match the header. Check spelling and case.
  • All results are zero or wrong. You may be using Duration.Hours instead of Duration.TotalHours, or the source values are not real durations. Inspect a single cell in the formula bar.
  • The column shows a date instead of a number. The output type was set to Date/Time. Change the column type to Decimal Number.
  • Refresh fails after loading. A step earlier in the query changed a column name or type. Open the Applied Steps and check the step just before the custom column.
  • Values look right in the editor but wrong in the sheet. The cell format in Excel may be applying a time format. Format the loaded column as a number.

Frequently Asked Questions

What does Duration.TotalHours return?

A decimal number representing the entire duration in hours. A duration of 1 day and 12 hours returns 36.

How is it different from Duration.Hours?

Duration.Hours returns only the hour component, from 0 to 23. Duration.TotalHours returns the full span converted to hours, including days and minutes.

Can I use it on a text column?

No. Convert the column to Duration first, or parse the text with the Duration from Text option in the Transform tab.

How do I get whole hours only?

Wrap the call in a rounding function, for example Number.RoundDown(Duration.TotalHours([Duration])).

Does it work in Excel and Power BI?

Yes. The function is part of the standard M library used by both, so the formula is the same.

Why do I get an error about the field not being found?

The column name in the formula does not match the actual header. M is case-sensitive, so copy the name exactly.