Power Query Duration.Seconds: How to Use It
In this article
Duration.Seconds converts a duration value into a whole number of seconds. In Power Query (the data transformation engine inside Excel and Power BI), a duration is stored as a decimal number of days, so Duration.Seconds multiplies that value by 86,400 and returns the integer part. The function does not round — it truncates toward zero — and it ignores any fractional seconds. Use it when you need a clean, whole-second count for sorting, filtering, or feeding into another calculation, such as converting call lengths, machine run times, or elapsed timestamps into seconds for aggregation.
What You'll Need
- Excel (Microsoft 365 or Excel 2019 and later) or Power BI Desktop with the Power Query Editor available.
- A column or value that is already a duration type, or a way to create one (for example, by subtracting two datetime values).
- Basic familiarity with adding a custom column or editing the formula bar in Power Query.
Step-by-Step
- Open Power Query Editor. In Excel, select your data and go to Data > From Table/Range. In Power BI Desktop, use Home > Transform data. Menu labels can differ slightly by version and region.
- Confirm you have a duration value. Duration.Seconds expects a duration, not text or a plain number. If your column holds text like "00:05:30", first convert it: select the column, then use Transform > Data Type > Duration. If the column is the result of subtracting two datetime columns, Power Query already treats it as a duration.
- Add a custom column. Go to Add Column > Custom Column. Give it a name such as "Seconds".
- Enter the formula. In the formula box, type
Duration.Seconds([YourColumn]), replacing[YourColumn]with the exact name of your duration column. Column names are case-sensitive in M, so match the name exactly. - Check the preview. The custom column dialog shows a preview table. Verify that a known duration, such as 0.00:01:30 (one minute thirty seconds), returns 90. If it returns an error, the input is not a duration type — go back to step 2.
- Click OK. The new column appears with the ABC/123 icon indicating a number type. Power Query usually infers the type automatically; if not, select the new column and set Data Type > Whole Number.
- Handle nulls if needed. If the source column can be null, wrap the formula:
if [YourColumn] = null then null else Duration.Seconds([YourColumn]). This avoids errors in downstream steps. - Load the result. Use Home > Close & Load (Excel) or Home > Close & Apply (Power BI) to bring the transformed table back into your workbook or model.
Common Mistakes
- Passing text instead of a duration. Duration.Seconds("00:01:30") returns an error because the argument must be a duration value, not a string. Convert the column type first.
- Expecting rounding. Duration.Seconds truncates. A duration of 90.9 seconds returns 90, not 91. If you need rounding, combine it with Number.Round:
Number.Round(Duration.TotalSeconds([YourColumn])). - Confusing Duration.Seconds with Duration.TotalSeconds. Duration.Seconds returns only the seconds component of the duration (0–59) when the duration is expressed in its component parts, whereas Duration.TotalSeconds returns the entire duration converted to seconds. For a duration of 1 minute 30 seconds, Duration.Seconds returns 30, but Duration.TotalSeconds returns 90. Choose based on whether you want the component or the total.
- Case and spelling errors in column names. M is case-sensitive;
[duration]and[Duration]are different references and one will fail. - Forgetting to set the data type. If the custom column is left as Any, later steps such as sorting or aggregating may behave unexpectedly. Set it to Whole Number.
Tips
- Use Duration.TotalSeconds when you need the full elapsed time in seconds; use Duration.Seconds when you specifically want the seconds portion of a clock-style duration.
- To convert seconds back into a readable duration, use
#duration(0, 0, 0, [Seconds])and set the column type to Duration. - Name custom columns clearly (for example "CallSeconds") so the formula stays readable when you revisit the query later.
- If you are working with timestamps, subtract the start from the end first (for example
[EndTime] - [StartTime]) to produce a duration, then apply Duration.Seconds or Duration.TotalSeconds. - Test with a known value before applying the step to the whole column — the preview in the Custom Column dialog is the fastest way to catch type errors.
Troubleshooting
- Error: "We cannot convert the value ... to type Duration." The column is not a duration. Change its data type to Duration, or use Duration.FromText if the source is a text timestamp in a recognized format.
- Error: "The field 'YourColumn' of the record wasn't found." The column name is misspelled or has different capitalization. Check the exact header in the preview.
- Results look wrong (for example, 30 instead of 90). You likely want Duration.TotalSeconds, not Duration.Seconds. The latter returns the seconds component only.
- Nulls produce errors. Add the null check shown in step 7, or use try/otherwise:
try Duration.Seconds([YourColumn]) otherwise null. - The step works in the editor but fails on refresh. The source data may have changed type (for example, a text value appeared in a duration column). Re-check the source column type and add a type conversion step before the custom column.
- If that did not work, delete the custom column, re-check the source column's data type, and rebuild the step from scratch. If the query still fails, use the Applied Steps pane to click through each step and find the first one showing an error.
Frequently Asked Questions
What is the difference between Duration.Seconds and Duration.TotalSeconds?
Duration.Seconds returns the seconds component of a duration (0–59 when the duration is broken into hours, minutes, and seconds). Duration.TotalSeconds returns the entire duration expressed as a total number of seconds. For 1 minute 30 seconds, they return 30 and 90 respectively.
Does Duration.Seconds round or truncate?
It truncates toward zero. A duration of 90.9 seconds returns 90. Use Number.Round with Duration.TotalSeconds if you need rounding.
Can I use Duration.Seconds on a text column?
No. The argument must be a duration value. Convert the column to Duration first (Transform > Data Type > Duration), or use Duration.FromText if the text is in a recognized duration format.
Why does my custom column show an error for some rows?
Those rows likely contain nulls or values that are not durations. Add a null check or a try/otherwise expression to return null instead of an error.
How do I convert seconds back into a duration?
Use #duration(0, 0, 0, [Seconds]) and set the column data type to Duration. This creates a duration of that many seconds.
Is Duration.Seconds available in both Excel and Power BI?
Yes. Both Excel Power Query and Power BI Desktop use the same M engine, so the function behaves the same in each, though menu labels may differ slightly by version.