Splitter.SplitTextByDelimiter Function in Power Query

The Splitter.SplitTextByDelimiter function in Power Query's M language creates a splitter function that divides a text string into a list of text segments based on a specified delimiter. It is commonly used in transformations like Table.SplitColumn to split text data into multiple columns or lists.

Syntax

Splitter.SplitTextByDelimiter(
    delimiter as text, 
    optional quoteStyle as nullable number, 
    optional csvStyle as nullable number
) as function

The function has the following parameters:

The function returns a function that can be applied to a text value to perform the split.

How It Works

Example: Basic Splitting. Split the text "a,b,c,d" by commas without considering quotes.

Power Query M

let
    Source = Splitter.SplitTextByDelimiter(",", QuoteStyle.None)("a,b,c,d")
in
    Source      

The output of the above code is {"a", "b", "c", "d"}. The text is split at each comma.

Example: Split the input by comma, handling quoted text. Split the text "a,""b,c"",d" by commas, respecting CSV-style quotes.

Power Query M

let
    Source = Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv)("a,""b,c"",d")
in
    Source    

The output of the above code is {"a", "b,c", "d"}.

How it works: Here we have used QuoteStyle.Csv.

Example: Consecutive Delimiters. Split the text "a,,b,c" by commas.

Power Query M

let
    Source = Splitter.SplitTextByDelimiter(",", QuoteStyle.None)("a,,b,c")
in
    Source       

The output of the above code is {"a", "", "b", "c"}. Consecutive commas result in an empty string "" between "a" and "b".

Example: Using with Table.SplitColumn. Suppose we have a table with a column "Data" containing a string, and we want to split it into multiple columns by delimiter hyphen.

Power Query M

let
  Source = Table.FromRecords(
    {
      [Data = "1-Ashish-568"], 
      [Data = "2-Katrina-855"], 
      [Data = "3-Alia-380"], 
      [Data = "4-Vicky-458"], 
      [Data = "5-Mohini-278"], 
      [Data = "6-Meenakshi-289"], 
      [Data = "7-Esha-875"], 
      [Data = "8-Anjali-380"]
    }
  ), 
  return = Table.SplitColumn(Source, "Data", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"CustomerID", "Name", "Marks"})
in
    return        

The text is split at hyphen (-), creating three columns.

Splitter.SplitTextByDelimiter Function in Power Query

Practical Use Cases