At the end of the Power Query Formula Library Specification (which can be downloaded here) are sections on Comparer, Combiner, Replacer and Splitter functions. These functions are most often used in conjunction with other functions like Table.CombineColumns() and Table.SplitColumn, but what you may not realise from the documentation (which also has a few minor but nonetheless confusing bugs in it) is what these functions do: they are functions that return functions, and the functions that they return can be used independently just like any other function.
Take Splitter.SplitTextByDelimiter() as an example. It returns a function that splits a piece of text by a delimiter, and returns a list containing the resulting pieces. The following M code calls this function to return a function that splits comma delimited text:
let
demo = Splitter.SplitTextByDelimiter(",")
in
demo
As noted here, once you have a query that returns a function you can see that function’s signature and invoke it from the Query Editor window. Here’s what the query above shows in the Query Editor window:
If you click the Invoke button and enter the text
one,two,three,four
As follows:
So that the code for the query becomes:
let
demo = Splitter.SplitTextByDelimiter(","),
Invokeddemo = demo("one,two,three,four")
in
Invokeddemo
What is returned is the list {“one”, “two”, “three”, “four”} which looks like this in the Query Editor window:
There are various other Splitter functions that can be used to return functions that split text in different ways. Similarly, the Combiner functions return functions that can be used to combine a list of text into a single piece of text. For example:
let
demo = Combiner.CombineTextByDelimiter("--"),
Invokeddemo = demo({"one","two","three","four"})
in
Invokeddemo
Returns the text
one–two–three—four
The Replacer functions return functions for replacing values in text , while the Comparer functions return functions that can be used for comparing text using specific cultures and case sensitivities.