Forum Discussion
remove string patterns within a column
- 2 years ago
The simplest thing to do, if there are not too many different codes, would be to right-click and Replace Values. Do that multiple times for each different code. It's simple but maybe not appropriate
--
There is no built-in regular expression functions in power query but you can make web calls to do this from within PQ. It's not going to be quick but it does open up the whole power of regex. Here's an example thread
--
Alternatively, you can define a list of all possible codes to search for, then use that list in a function to clean the column:
1 Make a list {1..999}
2 Transform it to codes : List.Transform(Source, each Text.Combine({"s:", Text.From(_), ":"}))
then add a column to the original query using :List.Accumulate( SearchList, {[Column1], ""}, (old, current) => let CreateNew = Text.Replace(old{0}, current,""), CreateSubstringsRemoved = try Text.Combine (List.Difference(Text.ToList (old{0}), Text.ToList(CreateNew) ) ) otherwise "" in {CreateNew, if CreateSubstringsRemoved <> "" and old{1} <> "" then old{1} & ", " & CreateSubstringsRemoved else if old{1} <> "" and CreateSubstringsRemoved = "" then old{1} else CreateSubstringsRemoved } ) {0}I didn't write that originally, it's by a contributor who used to be on the forum
Jimmy801
More detail please. Show your data and the desired result please