Forum Discussion

GiveMeArrays's avatar
GiveMeArrays
Frequent Visitor
4 years ago
Solved

Correct Syntax for Table.TransformColumns + Text.Length + Text.Combine

Please help with syntax guidance for the following M code:   = Table.TransformColumns( #"table" , { "column", each if Text.Length(_) = 4 then _ else Text.Combine( {"0",_} ) } )   Result: Expressi...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi GiveMeArrays - You could consider using Text.PadStart like this:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI3VorViVYyNjExBTNMjYxNYSJg2sRIKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}}),
        #"Added to Column" = Table.TransformColumns(#"Changed Type", {{"Column1", each Text.PadStart( Text.From(_) ,4 , "0" ) , type text }})
    in
        #"Added to Column"