Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This sample uses a header consisting of dashes to identify where the column boundaries are and then splits the file by those boundaries.
let
Source = Table.FromColumns({Lines.FromBinary(Web.Contents("http://www.aer.ca/data/WELLS/SPUDTHU.TXT"),null,null,1252)}),
Header = List.First(List.Select(Source[Column1], each Text.StartsWith(_, "--"))),
Positions = Text.PositionOf(Header, " ", -1),
Length = Text.Length(Header),
Lengths = List.Generate(
() => 0,
(i) => i <= List.Count(Positions),
(i) => i + 1,
(i) =>
let
start = if i = 0 then -1 /* to capture trailing space */ else Positions{i-1},
end = if i = List.Count(Positions) then Length else Positions{i}
in
end - start),
Split = Table.SplitColumn(Source,"Column1",Splitter.SplitTextByLengths(Lengths))
in
Split
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment