Hi,
I have a data column of customer references that comprise a (constant) letter followed by one or more digits (up to five) and I'd like to pad the digits to give the same length.
Eg A1 becomes A00001 and A44 becomes A00044.
I've done this by multiple operations and just wondered if it's possible to do it all in one - and would this be more efficient? Should I create a function or is there a simpler way?
My current M-code is:
let
Source = Excel.CurrentWorkbook(){[Name="tblSample"]}[Content],
#"Split Column by Positions" = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByPositions({0, 1}), {"First", "Rest"}),
#"Added Custom Column" = Table.AddColumn(#"Split Column by Positions", "Pad", each Text.PadStart([Rest], 5, "0"), type text),
#"Merged Columns" = Table.CombineColumns(#"Added Custom Column",{"First", "Pad"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"SplitAndPadded"),
#"Removed Columns" = Table.RemoveColumns(#"Merged Columns",{"Rest"})
in
#"Removed Columns"
Thanks in advance.
Pieter
Hi Pieter,
It won't make any difference if you create this as a custom function, the steps will be the same therefore there won't be any efficiency gains. I'd be inclined to leave it as is so you can easily see the steps being applied, rather than rolling it into a function.
Mynda
Hy Mynda,
Great advice - many thanks.
Pieter