- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

M Language - convert duration to seconds
Apologies, but I really don't know M at all and I've run into difficulties with time and duration. I have a table with, amongst other things, 15 columns of durations in the format xx:xx:xx . I currently have these 15 columns as a strings. I'd like to know the custom function to convert this to seconds - i.e., (number before first : delimiter * 3600) + (number between first and second : delimiter *60 ) + number after last delimiter.
I can do this in Excel with LEFT, MID, LEN and FIND, and I guess I could do the same as calculated columns in DAX, but I don't know how to do it in Power Query with M. Is it quicker to do it that way?
I haven't upoad a pbi file here as I'm hoping it's quite a self-explanatory question.
Many thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

If you look on the right hand side of this web page, you'll see a 'Recommendations' panel and they might help you.
Alternatively, if you get the column into a duration data type, you can use function:
https://learn.microsoft.com/en-us/powerquery-m/duration-totalseconds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

You can either add a column or transform the existing column.
- Ensure your dataColumn is type as a duration
- To add a column, navigate to the Add Custom Column item and, for a formula:
=Duration.TotalSeconds([dataColumn])
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

If you look on the right hand side of this web page, you'll see a 'Recommendations' panel and they might help you.
Alternatively, if you get the column into a duration data type, you can use function:
https://learn.microsoft.com/en-us/powerquery-m/duration-totalseconds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Thanks. They're all about how to do it in DAX though, and I think I can do that. I'm trying to do it in M/Power Query, rather than going through the process of 'copy column, split by delimiter, do arithmetic, delete columns again' 15 times. Sorry, guess I'm being lazy!

Helpful resources
Subject | Author | Posted | |
---|---|---|---|
12-07-2018 11:58 AM | |||
02-18-2025 01:22 AM | |||
09-18-2023 01:52 PM | |||
03-21-2018 07:34 AM | |||
Anonymous
| 03-08-2024 02:02 AM |
User | Count |
---|---|
33 | |
18 | |
14 | |
11 | |
10 |