Forum Discussion

PowerBI_Query's avatar
PowerBI_Query
Icon for Helper II rankHelper II
4 years ago
Solved

Add leading zero to a column value and concatenate with other value in place.

I want to add leaing zero's if the number lenght is less than 9 digits in Column3 (after adding leading zero it can be in text format to retain the zeros). Then I want to concatenate it with values i...
  • Vijay_A_Verma's avatar
    4 years ago

    Issue this statement where you will need to replace Changed Type with your previous step. 

     

    = Table.ReplaceValue(#"Changed Type",each [Column3], each Text.From([Column1])&Text.PadStart(Text.From([Column3]),9,"0"),Replacer.ReplaceValue,{"Column3"})

     

    I can see a space between concatenated value in your result column. I haven't put a space in above formula. If you need a space, use below formula

     

    = Table.ReplaceValue(#"Changed Type",each [Column3], each Text.From([Column1])&" "&Text.PadStart(Text.From([Column3]),9,"0"),Replacer.ReplaceValue,{"Column3"})

     

    See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNTUzNzdX0lFySS1OLsosKMnMzzMEcg2NTcwtLM2VYnWilUxNsakyQlYVCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", type text}, {"Column3", Int64.Type}}),
        Custom1 = Table.ReplaceValue(#"Changed Type",each [Column3], each Text.From([Column1])&Text.PadStart(Text.From([Column3]),9,"0"),Replacer.ReplaceValue,{"Column3"})
    in
        Custom1