Forum Discussion

boa's avatar
boa
Helper I
3 years ago
Solved

Time.FromText gives sometimes an error

Hello I'm new to PowerQuery. I have a simple question. I want to change a column with the time in (format is text) to a time format. I used "Time.FromText"-function in PowerQuery. This is not alway...
  • AntrikshSharma's avatar
    3 years ago

    boa You can use this:

    let
        Source = 
            Table.FromRows (
                Json.Document (
                    Binary.Decompress (
                        Binary.FromText (
                            "i45WMjQ2NlaK1QEyLEwNwQwDMyNTMMPSwABMm0IoIwMo3xCkIxYA",
                            BinaryEncoding.Base64
                        ),
                        Compression.Deflate
                    )
                ),
                let
                    _t = ( ( type nullable text ) meta [ Serialized.Text = true ] )
                in
                    type table [ Time = _t ]
            ),
        AddedCustom = 
            Table.AddColumn (
                Source,
                "Custom",
                each 
                Time.FromText ( 
                    Text.PadStart ( [Time], 4, "0" ) 
                ),
                Time.Type
            )
    in
        AddedCustom