Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Text.SplitAny: Split Text by Delimiters

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Text.SplitAny splits a text value into a list of pieces wherever any character from a delimiter set appears. It is the Power Query M function you reach for when one string contains several possible separators (for example a comma, semicolon or pipe) and you want a clean list of parts. You do not need to install anything extra: it is part of the built-in M language and works in Power Query Editor inside Excel, Power BI Desktop and other Microsoft tools that host Power Query. The shortest working pattern is Text.SplitAny("a,b;c", ",;"), which returns {"a","b","c"}.

What You'll Need

  • A tool that includes Power Query Editor, such as Excel or Power BI Desktop.
  • A query with a text column, or a blank query where you can type M code directly.
  • Basic familiarity with the Power Query Editor and the formula bar or Advanced Editor.

Step-by-Step

  1. Open Power Query Editor. In Excel, select a cell in your data and use Data > Get & Transform Data > From Table/Range. In Power BI Desktop, use Home > Transform data. Menu labels can differ slightly by version, device or region.
  2. Load or create the text you want to split. If you are experimenting, use Home > New Source > Blank Query, then open the Advanced Editor and enter a simple expression such as let Source = "red,green;blue|yellow" in Source.
  3. Decide which characters should act as separators. Text.SplitAny treats every character in the delimiter string as a separate delimiter, not as a multi-character sequence. For example, passing ",;|" splits on a comma, a semicolon or a pipe.
  4. Call the function. The syntax is Text.SplitAny(text as text, separators as text) as list. In a query step it looks like Text.SplitAny(Source, ",;|"). The result is a list, not a single text value.
  5. Turn the list into usable columns. Select the step result and use the list-to-table button in the formula bar area, or wrap it with Table.FromList. A common pattern is Table.FromList(Text.SplitAny(Source, ",;|"), Splitter.SplitByNothing(), {"Part"}).
  6. Expand or transform the resulting column. If you need to split an existing column row by row, add a custom column with Text.SplitAny([ColumnName], ",;|"), then expand the new list column using the expand icon in the column header.
  7. Clean up the output. Text.SplitAny does not trim spaces or remove empty entries. Add List.Transform(..., Text.Trim) to trim each part, or List.Select(..., each _ <> "") to drop blanks.
  8. Rename and reorder the columns, then close and load the query using Home > Close & Load (Excel) or Home > Close & Apply (Power BI Desktop).

Common Mistakes

  • Expecting multi-character delimiters. Text.SplitAny splits on each individual character. To split on a whole word or phrase such as "--" as one unit, use Text.Split with a list of delimiters instead.
  • Forgetting that the result is a list. Pasting the function directly into a column without converting or expanding the list leaves you with a list value, not readable text.
  • Ignoring spaces. A string like "a, b, c" produces parts with leading spaces. Trim them explicitly.
  • Leaving empty entries. Consecutive delimiters create empty strings in the list. Filter them out if they are not meaningful.
  • Passing the wrong argument type. Both arguments must be text. A null value or a number will raise an error, so guard with try ... otherwise or replace nulls first.

Tips

  • Use a delimiter string that covers every separator that actually appears in your data, including line breaks if needed. In M, a line break can be represented with "#(lf)".
  • Combine Text.SplitAny with List.Distinct if you only want unique parts, or with List.Count to count how many pieces a string produced.
  • If you need to split on a fixed number of characters rather than delimiters, use Text.Split instead; Text.SplitAny is specifically for character-based delimiter sets.
  • Test the function on a blank query first so you can see the list output before applying it to a real column.
  • Keep the delimiter string in one place, such as a query parameter, so you can change it without editing every step.

Troubleshooting

If the function returns an error, check that both arguments are text and that the first argument is not null. If the output looks like a single item instead of several, confirm that the delimiter string actually contains the characters present in your data. If you see spaces or empty values, add trimming and filtering steps as described above. If the query is slow on a large table, consider splitting only the rows you need or using Text.Split with a fixed list of delimiters, which can be easier for the engine to process. If the list-to-table step fails, make sure you are applying it to a list value and not to a table or record. When a step does not behave as expected, use the Applied Steps pane to inspect the output of each step one at a time.

Frequently Asked Questions

What is the difference between Text.Split and Text.SplitAny?

Text.Split splits on each full string in a list of delimiters, so a delimiter can be multiple characters. Text.SplitAny splits on every individual character in a single delimiter string.

Can Text.SplitAny split on a space?

Yes. Pass a space inside the delimiter string, for example Text.SplitAny(text, " "). Consecutive spaces will produce empty entries, which you can remove with List.Select.

Does Text.SplitAny remove empty values automatically?

No. It returns every segment, including empty strings between adjacent delimiters. Filter them out if needed.

Can I use Text.SplitAny on a column in Power Query?

Yes. Add a custom column with the function and reference the column name, then expand the resulting list column.

Is Text.SplitAny available in Excel and Power BI?

Yes, it is part of the M language used by Power Query in both Excel and Power BI Desktop, as well as other Microsoft products that host Power Query.

What happens if the delimiter string is empty?

An empty delimiter string means there are no characters to split on, so the function returns the original text as a single-item list.