Created
February 7, 2024 01:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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