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
JoseHop
Helper I
Helper I

How do I convert time from 32102,222 to real decimal number

I use data from a database with price and hours. 

for instance: price is 27,14 hours are 3h21min2,222sec 

In power bi: 27,14 and 32102,222

How do I get the time in decimal number like this? : 3,35061722

 

1 ACCEPTED SOLUTION

Hi @JoseHop ,

 

*EDIT* Having looked at your previous post, I think this should paste straight into your query as a new custom column:

 

let
  hours = Number.Round([PRIJS_PERIODE.PRODUCT_KIND_VAST.DINSDAG_UREN] / 10000),
  minutes = Number.Round(([PRIJS_PERIODE.PRODUCT_KIND_VAST.DINSDAG_UREN] - hours * 10000) / 100),
  seconds = [PRIJS_PERIODE.PRODUCT_KIND_VAST.DINSDAG_UREN] - (hours * 10000) - (minutes * 100)
in
  hours + (minutes * 60 + seconds) / 3600)

 

 

No, I was after a visual of what the values actually look like in PQ. It's fine though, not a problem.

Add this in a new custom column, assuming your original value is in a column called [time]:

 

 

let
  hours = Number.Round([time] / 10000),
  minutes = Number.Round(([time] - hours * 10000) / 100),
  seconds = [time] - (hours * 10000) - (minutes * 100)
in
  hours + (minutes * 60 + seconds) / 3600)

 

 

 

This gives me the following output:

BA_Pete_0-1660140912577.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

6 REPLIES 6
ronrsnfld
Super User
Super User

Add Custom Column Formula:

 

let 
   hrs = Number.IntegerDivide([Hours],10000),
   mins = Number.IntegerDivide([Hours] - hrs * 10000,100),
   secs = Number.Mod([Hours], 100)
in Duration.TotalHours(#duration(0,hrs, mins, secs))

 

 

To Reproduce:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLXMTRR0lEyNjI0MNIxMjJSio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Price = _t, Hours = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Price", Currency.Type}, {"Hours", type number}},"en-DE"),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Decimal Hours", each 
        let 
            hrs = Number.IntegerDivide([Hours],10000),
            mins = Number.IntegerDivide([Hours] - hrs * 10000,100),
            secs = Number.Mod([Hours], 100)
        in 
            Duration.TotalHours(#duration(0,hrs, mins, secs)))
in
    #"Added Custom"

 

ronrsnfld_0-1660140148214.png

 

 

hi ronrsnfld, thnx for your answer. The formula looks oke but when I add this then I will get an error.

Probalby I do something wrong:

JoseHop_0-1660140121813.png

 

It appears you do not have a column named Hours.  Since you posted no data, I used obvious column names. You will need to change it to the actual column

JoseHop
Helper I
Helper I

Hi Pete, thnx voor your quick response. 

I hope I understand your question.

Is this what you are looking for?:

 

= Table.TransformColumnTypes(Bron,{{"PRIJS_PERIODE.PRODUCT_KIND_VAST.DINSDAG_UREN", type number}})

Hi @JoseHop ,

 

*EDIT* Having looked at your previous post, I think this should paste straight into your query as a new custom column:

 

let
  hours = Number.Round([PRIJS_PERIODE.PRODUCT_KIND_VAST.DINSDAG_UREN] / 10000),
  minutes = Number.Round(([PRIJS_PERIODE.PRODUCT_KIND_VAST.DINSDAG_UREN] - hours * 10000) / 100),
  seconds = [PRIJS_PERIODE.PRODUCT_KIND_VAST.DINSDAG_UREN] - (hours * 10000) - (minutes * 100)
in
  hours + (minutes * 60 + seconds) / 3600)

 

 

No, I was after a visual of what the values actually look like in PQ. It's fine though, not a problem.

Add this in a new custom column, assuming your original value is in a column called [time]:

 

 

let
  hours = Number.Round([time] / 10000),
  minutes = Number.Round(([time] - hours * 10000) / 100),
  seconds = [time] - (hours * 10000) - (minutes * 100)
in
  hours + (minutes * 60 + seconds) / 3600)

 

 

 

This gives me the following output:

BA_Pete_0-1660140912577.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




BA_Pete
Super User
Super User

Hi @JoseHop ,

 

Can you provide a visual example of what your original format looks like and exactly how it looks in PQ, including data types please?

Even better, if you can provide an example of your data by using the 'Enter Data' function and pasting the M code here, we can get you a solution even faster.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




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.

Top Solution Authors
Top Kudoed Authors