Skip to content

Instantly share code, notes, and snippets.

@ncalm
Created February 7, 2024 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncalm/fba7dca10c44307d24a7f99fe0e0bbfa to your computer and use it in GitHub Desktop.
Save ncalm/fba7dca10c44307d24a7f99fe0e0bbfa to your computer and use it in GitHub Desktop.
This code demonstrates one way to parse a string of fields into multiple rows and columns
let
Source = "APS Deposit 04/01/2022 $5,174.27 APS ACH Deposit 04/04/2022 $65,186.66",
Split = Text.Split(Source, " "),
Typed = List.Transform(Split,
each try Number.From(_) otherwise
try Date.From(_, "en-gb") otherwise _ ),
Accumulate = List.Accumulate({0..List.Count(Typed)-1}, "",
(a, b) =>
let
c = Typed{b},
p = try Typed{b-1} otherwise "",
d = if p = "" then ""
else
if c is text then
if p is text then " " else ";"
else ","
in
a & d & Text.From(c)
),
SplitToRows = Text.Split(Accumulate, ";"),
SplitToColumns = List.Transform(SplitToRows,
each Text.Split(_, ",")),
AsTable = Table.FromRows(SplitToColumns,
{"Description", "Date", "Amount"}),
Result = Table.TransformColumnTypes(
AsTable,
{
{"Description", type text},
{"Date", type date},
{"Amount", Currency.Type}
})
in
Result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment