Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Goodkat
Helper II
Helper II

Cache Text.Split / List Select line for multiple evaluation

Dear Power Query Enthusiasts,


Last night I had an idea how to improve some text string cleaning and editing. I do split a string with SplitAny to enable for multiple delimiters, then check if the last word matches a key word and if yes, combine the list back into a text, EXCEPT this last position. It works. But I realized, that I must use the core component
List.Select(Text.SplitAny([hea], " _"), each _ <> "")
Three times (perspectively even more often) in this procedure.

And here I questioned myself, but could nothing find in the internet, if I could wrap the core component into a List.Buffer statement and subsequently only reference that. I tried but it did not work.


Sample file can be found here: https://c.gmx.net/@324888734501700174/gC3MEGn8wu7DQH0H_bXjKg

 

Does the forum have any conclusive idea how to achieve that?

 

Thank you!

 

Best regards, Andreas

1 ACCEPTED SOLUTION

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]
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

5 REPLIES 5
jgeddes
Super User
Super User

Can you provide examples of the intended output of the list provided in the file?
It will help to shape the code required.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





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

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
    )




Did I answer your question? Mark my post as a solution!

Proud to be a 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]
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.