Power Query M Language-Convert Seconds to HH:MM:SS Format in Power BI

M-language-seconds - HHMMSS

Table of Contents

Power Query M Language-Convert Seconds to HH:MM:SS Format in Power BI

Power Query M Language-Convert Seconds to HH:MM:SS Format in Power BI

I got a scenario to convert the Seconds to HH:MM:SS in Power BI.

Step 1: Click on Edit Query and go to the query having seconds in the Column. Below is the screenshot of the Query. The table is “TimeTable” and Column having second Value is “Seconds”

Seconds to HH:MM:SS In Power BI

Step 2: Go to Add Column Tab and create a custom column  and write the M Script Code #duration(0,0,0,[Seconds])

M Script code for converting Seconds to HH:MM:SS

Step 3: You will be getting values like the below screenshot in the new custom column.

Step 4:  Close the Power Query and come to Data Tab in Power BI Desktop. You will now see the values in Time Column in Decimal Format.

Step 5: In Data Tab, Go to Modelling Tab and change the Data type of Time Column to  “Time” and format to HH:MM: SS.

As per the above screenshot, You have successfully converted the Seconds to HH:MM: SS time format.

You can also change the Seconds to HH:MM: SS time format using DAX using simple mathematical calculation but that process is a little complex than the process mentioned above.

Please do comment if you find any error in this article or able to find any other way to achieve the same result.

Thank you.

Kaushlendra Mishra

What are Indexes in SQL Database? What is the advantage and disadvantage of Indexes?

Indexes are schema objects in a SQL database that can boost query performance while executing queries with a filter condition using where clause.

Indexes are used to retrieve data from databases very fast. An Index is a quick lookup table that is used to find a record that user search very frequently. An index helps to speed up select queries and where clauses, but it slows down data input, with the update and the insert statements.

Read More »

5 thoughts on “Power Query M Language-Convert Seconds to HH:MM:SS Format in Power BI”

  1. You can achieve your requirement through steps mentioned in this article. If seconds are given in a column then easily you can create a seperate column having value in hh:mm:ss format.

    Please follow the article.

  2. Question: First of all, this is great! Thank you! Thankfully, if it's longer than 24 hours, it turns the excess into days (d.hh:mm:ss). Is there a way to change the hours of the day so that if it's at x amount of hours it turns to a day? I'm wanting to change once it gets to 12 hours so for example if it was 13 hours, it'd look like 1.01:00:00. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *