Nick Burns
Member
- Joined
- May 24, 2017
- Messages
- 162
- Reaction score
- 0
- Points
- 16
- Excel Version(s)
- Office 365
= Table.TransformColumns(Source, List.Transform(PadColumns, each {_, (a)=>Text.PadStart(a,PadLengths{List.PositionOf(PadColumns,_)}," ")}))
Thanks, that's just the "nudge" I needed to get my solution. I was able to make the Paddings into a list of lists and using your code came up with this:If you load your Paddings table into two lists, PadColumns and PadLengths, then you can do this:
Code:= Table.TransformColumns(Source, List.Transform(PadColumns, each {_, (a)=>Text.PadStart(a,PadLengths{List.PositionOf(PadColumns,_)}," ")}))
= Table.TransformColumns(Source, List.Transform(ColumnPaddings, each {_{0}, (a)=>Text.PadStart(a,_{1}," "),type text}))
= Table.TransformColumns(Source, List.Transform(ColumnPaddings, each if _{2}="0" then {_{0}, (a)=>Text.PadStart(a,_{1},"0"),type text} else {_{0}, (a)=>Text.PadEnd(a,_{1}," "),type text}))
let
Source = Excel.CurrentWorkbook(){[Name="Paddings"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column Name", type text}, {"Length", Int64.Type}, {"Fill", type text}}),
#"Added Custom" = Table.AddColumn(Source, "Function", each if [Fill] = "0" then Text.PadStart else Text.PadEnd),
#"Trimmed Text" = Table.TransformColumns(#"Added Custom",{{"Fill", each if _ = "BLANK" then " " else _, type text}}),
#"Added Custom1" = Table.AddColumn(#"Trimmed Text", "Custom", each Record.ToList(_)),
Custom = #"Added Custom1"[Custom]
in
Custom
= Table.TransformColumns(Source, List.Transform(ColumnPaddings, each {_{0}, (a)=>_{3}(a,_{1},_{2}),type text}))