Forum Discussion

dananjayaprasad's avatar
8 years ago
Solved

Convert Data Type to time or Duration

Hello ,    I have a time period that I need to covernt in to a time period on PowerBI, but it gives me a error, I tried sever ways did not work. I am kinda stumped. I would really appreciate if any...
  • MarcelBeug's avatar
    MarcelBeug
    8 years ago

    DHana, please understand that a time value is 1 timestamp; if converted to a number then it will be between 0 and 1.

    A Time Period like yours is just text.

     

    Having said that, in the Query Editor: Add Column - Extract - Text Before Delimiter: delimiter <space>, advanced, skip 1.

    Rename the column to Start Time and adjust the data type to Time.

     

    Close & Load. In the Data view, tab Modeling, select Time Period and sort by Column Start Time.

     

    Generated query code (the first 2 steps just create the table):

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jc+9CsMwDATgVzGe06JzfmxlC5kD3kOGjKVb6dK3r2on9hJBB4E4+DhpXS2IzM3E/fU08+P9sY31o0TTIqkfe54WiVoZupPr7NZckVBI+JdwIXwSlwkGhYCKkfVAIaOh1RAqwolAWXnWlPupmJQTFZM6DmTtJ1RUTJcMoJDac1mzfQE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Location = _t, #"Time Period" = _t, Traffic = _t, #"% Traffic" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Time Period", type text}, {"Traffic", Int64.Type}, {"% Traffic", type number}}),
        #"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "Start Time", each Text.BeforeDelimiter([Time Period], " ", 1), type text),
        #"Changed Type1" = Table.TransformColumnTypes(#"Inserted Text Before Delimiter",{{"Start Time", type time}})
    in
        #"Changed Type1"