Forum Discussion
Cache Text.Split / List Select line for multiple evaluation
- 7 months ago
Is this along the lines of what you are looking for?
SplitAndCombine = Table.AddColumn( Quelle, "Test", each let codeBlock = List.Buffer(List.Select(Text.SplitAny([hea], " _"), each _ <> "")) in if List.Contains({"id", "key", "number"}, List.Last( codeBlock ), Comparer.OrdinalIgnoreCase) = true and List.Count( codeBlock ) > 1 then Text.Combine( List.RemoveLastN( codeBlock, 1 ), " ") else [hea] )
Can you provide examples of the intended output of the list provided in the file?
It will help to shape the code required.
Hi Jgeddes,
in the file behind the link in the Query 'Table1' Step 'SplitAndCombine' achieves the intended output. Step 'SplitAndBuffer' shall achieve the same, but with somehow buffering the List.Select(Text.SplitAny)) piece.
Best regards, Andreas
- jgeddes7 months ago
Super User
Is this along the lines of what you are looking for?
SplitAndCombine = Table.AddColumn( Quelle, "Test", each let codeBlock = List.Buffer(List.Select(Text.SplitAny([hea], " _"), each _ <> "")) in if List.Contains({"id", "key", "number"}, List.Last( codeBlock ), Comparer.OrdinalIgnoreCase) = true and List.Count( codeBlock ) > 1 then Text.Combine( List.RemoveLastN( codeBlock, 1 ), " ") else [hea] )- Goodkat7 months ago
Helper II
Dear Jgeddes,
Holy Smokes Sir!
That is exactly what I was looking to achieve! Super! And now I have a hands-on example of wrapping a 'let / in' statement within another 'let / in'. I had seen this before, but did not fully understand when and where I could use such construct. Now I know...
Thank you so much! You helped a ton and provided good insights to further bank on at my end!
Best regards, Andreas
- jgeddes7 months ago
Super User
Here is another possible solution that uses List.Difference(). You can test it on your data to see if it works faster/better for you.
Table.AddColumn( Source, "Test", each let keyWords = {"ID", "Key", "Number"}, delimters = {"_", " "}, nested = Text.SplitAny([hea], Text.Combine(delimters, "")) in if List.Count(nested) > 1 then Text.Combine(List.Difference(nested, keyWords, Comparer.OrdinalIgnoreCase), " ") else [hea], type text )