Forum Discussion

paolomint's avatar
paolomint
Helper III
5 years ago
Solved

Convert decimal in hour

Dear all, In my table there is a column with hour in decimal format: example 6,57 = 6:57 AM I tried to convert it in hours but it didn't work. How can I do that?  May I create a new column with t...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi paolomint ,

     

    Sorry for my late reply,

    let
        Source = #table(type table[Data = text],List.Zip({{"9,00","7,30","8,59","12,45","17,20"}})),
        #"Split Column by Delimiter" = Table.SplitColumn(Source, "Data", Splitter.SplitTextByAnyDelimiter({","}, QuoteStyle.Csv), {"Hour", "Minute"}),
        #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Hour", Int64.Type}, {"Minute", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Time.From(#datetime(1899, 12, 30, [Hour], [Minute], 12)))
    in
        #"Added Custom"

     

    If it is in decimal format, there is no comma in Power BI, so I think it may be in text format.

     

    The original data is text similar to 9,00. I first divide the hour and minute into two columns based on the comma, then convert the hour and minute columns into whole number types, and then convert them to time.

     

    You can check more details from here.

     

     

    Best Regards,

    Stephen Tao

     

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