Reputation: 379
I have a table that contains a text column in the following format:
"random text [ABC-######] other random text"
For all the rows containing "[ABC-" I would like to extract to a new column the "ABC-######" where ###### are random numbers at least 4 numbers but can be more.
this is what I got so far working:
= Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([TextColumn], "[ABC") then "FOUND" else "NotFound")
But I'm not able to extract the substring with numbers.
Can anyone help me please? Thank you dk
Upvotes: 2
Views: 9397
Reputation: 1530
let
tbl = #table({"TextColumn"}, {
{"qwer"},
{"qwer [ABC-1234] asdf"},
{"qwer [ABC-1234]"},
{"[ABC-1234] asdf"}
}),
AddColumn = Table.AddColumn(tbl, "ExtractedNumber", each try Splitter.SplitTextByEachDelimiter({"[ABC-","]"})([TextColumn]){1} otherwise "None")
in
AddColumn
Upvotes: 3
Reputation: 379
Solved using:
= Table.AddColumn(#"Changed Type", "Custom", each
if Text.Contains([TextColumn], "[ABC-") then
(Text.Range((Text.Range([TextColumn], (Text.PositionOf([TextColumn], "[ABC-", Occurrence.First))+1, 14)), 0, (Text.PositionOf((Text.Range([TextColumn], (Text.PositionOf([TextColumn], "[ABC-", Occurrence.First))+1, 14)), "]", Occurrence.First))))
else "None")
As suggested in the comments
Text.PositionOf
would result in being more fast.
Thanks
Upvotes: 1