Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ayoubb
Helper IV
Helper IV

converting hour format to seconds

plz could you help me to convert this: 00:06:30 to seconds in power bi

Thank you

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @ayoubb 

for average with @v-alq-msft solution you can try AVERAGE([TotalSecond column])

or

AVERAGEX(Table, HOUR([Time])*3600+MINUTE([Time])*60+SECOND([Time]) )


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hi, @ayoubb 

 

You mau try to create a custom in 'Query Editor' or create a calculated column/measure in Power BI Desktop. I created data to reproduce your scenario. The pbix file is attached in the end.

 

Table:

g1.png

 

Query Editor:
You may create a custom column as below.
g2.png

 

Here is the code in 'Advanced Editor'.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjCwMjCzMjZQitWBcCyQOZZWhqZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type time}}),
    Custom1 = Table.AddColumn(#"Changed Type","TotalSecond",each Time.Hour([Time])*3600+Time.Minute([Time])*60+Time.Second([Time])
)
in
    Custom1

 

Calculated column:

TotalSecond Column = HOUR([Time])*3600+MINUTE([Time])*60+SECOND([Time])

 

Or

 

Measure:

TotalSecond Measure = 
var _time = SELECTEDVALUE('Table'[Time])
return
HOUR(_time)*3600+MINUTE(_time)*60+SECOND(_time)

 

Result:

g3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

Thank you so much for your help, 

 

if i want to calculate the average of this colonne after using this formula : TotalSecond column = HOUR([Time])*3600+MINUTE([Time])*60+SECOND ([Time]) 

 

is it gona be: 

 

Average in seconds = Average ([Time])????

az38
Community Champion
Community Champion

Hi @ayoubb 

for average with @v-alq-msft solution you can try AVERAGE([TotalSecond column])

or

AVERAGEX(Table, HOUR([Time])*3600+MINUTE([Time])*60+SECOND([Time]) )


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Greg_Deckler
Super User
Super User

@ayoubb - See if this helps: https://community.powerbi.com/t5/Quick-Measures-Gallery/Duration-to-Seconds-Converter/m-p/342279#M92

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.