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
Anonymous
Not applicable

Concatenate and Fill in

Hi!

 

I'd like to concatenate and fill zero in a data using in power query, like the example below.

 

 

Column 1       Column 2     Column 3

 

45985381       1                  8

  5250111       2                  9 

    328111       4                 10 

 

Changed

 

New Column

45985371000108

05250111000209

00328111000410

 

Thanks,

1 ACCEPTED SOLUTION
stretcharm
Memorable Member
Memorable Member

Use the Pad and CombineColumns funtions

 

Text.PadStart(Text.From([Column1], "en-GB"), 8, "0")

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjG1tDA1tjBUgAAlHSVDILZQitWJVjI1MjUwNATxjYDYEixmbGQBETIBKTVQio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    Type = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}}),
    Pad1 = Table.AddColumn(Type, "Pad1", each Text.PadStart(Text.From([Column1], "en-GB"), 8, "0"), type text),
    Pad2 = Table.AddColumn(Pad1, "Pad2", each Text.PadStart(Text.From([Column2], "en-GB"), 4, "0"), type text),
    Pad3 = Table.AddColumn(Pad2, "Pad3", each Text.PadStart(Text.From([Column3], "en-GB"), 2, "0"), type text),
    #"Merged Columns" = Table.CombineColumns(Pad3,{"Pad1", "Pad2", "Pad3"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged")
in
    #"Merged Columns"

 

 

Also if you not sure of how to write a function try Add Column From Examples. This has a go at guessing what your want and writes the functions for you.

https://docs.microsoft.com/en-us/power-bi/desktop-add-column-from-example

View solution in original post

1 REPLY 1
stretcharm
Memorable Member
Memorable Member

Use the Pad and CombineColumns funtions

 

Text.PadStart(Text.From([Column1], "en-GB"), 8, "0")

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjG1tDA1tjBUgAAlHSVDILZQitWJVjI1MjUwNATxjYDYEixmbGQBETIBKTVQio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    Type = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}}),
    Pad1 = Table.AddColumn(Type, "Pad1", each Text.PadStart(Text.From([Column1], "en-GB"), 8, "0"), type text),
    Pad2 = Table.AddColumn(Pad1, "Pad2", each Text.PadStart(Text.From([Column2], "en-GB"), 4, "0"), type text),
    Pad3 = Table.AddColumn(Pad2, "Pad3", each Text.PadStart(Text.From([Column3], "en-GB"), 2, "0"), type text),
    #"Merged Columns" = Table.CombineColumns(Pad3,{"Pad1", "Pad2", "Pad3"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged")
in
    #"Merged Columns"

 

 

Also if you not sure of how to write a function try Add Column From Examples. This has a go at guessing what your want and writes the functions for you.

https://docs.microsoft.com/en-us/power-bi/desktop-add-column-from-example

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.