Smart Systems for Home

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

Power Query SplitTextByAnyDelimiter Guide

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Deep Dive: Splitter vs. Text Functions
  7. Frequently Asked Questions

To use the SplitTextByAnyDelimiter function in Power Query, you must implement it via the M formula language within a custom column or a transformation step, as it is a specialized splitter function rather than a standard button in the ribbon. This function is designed to handle datasets where a single column contains values separated by multiple, inconsistent characters—such as a mix of commas, semicolons, pipes, and dashes—allowing you to break those strings into clean, individual elements in one efficient operation.

What You'll Need

  • Microsoft Excel (with Power Query enabled) or Power BI Desktop.
  • A dataset containing "dirty" text strings where delimiters are not uniform.
  • Access to the Power Query Formula Bar or the Custom Column dialog box.
  • A clear understanding of the specific characters you intend to use as separators.

Step-by-Step

  1. Load your data: Open your Excel workbook or Power BI file. Select your data source, navigate to the Data tab (in Excel) or Home tab (in Power BI), and select From Table/Range or Get Data to launch the Power Query Editor window.
  2. Inspect the target column: Locate the column containing the messy text. Click the data type icon (e.g., ABC) next to the column header to ensure it is explicitly set to Text. If the column is set to 'Any' or 'General', the splitter functions may return errors.
  3. Access the Custom Column interface: Go to the Add Column tab on the top ribbon and select Custom Column. This is the safest way to test your formula without overwriting your original data.
  4. Construct the M Formula: In the Custom Column dialog, you will enter a formula. While the function Splitter.SplitTextByAnyDelimiter is often used within the Table.SplitColumn function for advanced users, the most practical way for most users to achieve this result is by using Text.SplitAny or by wrapping the splitter in a table transformation. For a new column that returns a list, use:
    = Text.SplitAny([YourColumnName], ",;|-").
    If you are editing a step in the Advanced Editor to split a column into multiple new columns using the formal splitter, the syntax looks like:
    = Table.SplitColumn(Source, "ColumnName", Splitter.SplitTextByAnyDelimiter({",", ";", "|"}), {"Col1", "Col2", "Col3"}).
  5. Define your delimiter list: When using the formal Splitter.SplitTextByAnyDelimiter, you must provide a list of strings inside curly brackets, such as {",", "|", ";"}. If you are using Text.SplitAny, you simply provide a single string containing all the characters you want to target, such as ",;|".
  6. Handle the resulting List: Once you click OK, the new column will show the word List in every cell. This is not an error; it means the function successfully grouped the split pieces into a collection. To turn these into actual columns, click the small icon with two diverging arrows at the top right of the new column header. Select Expand to New Rows if you want each item to have its own row, or Extract Values if you want them back in a single string with a different delimiter.
  7. Finalize Data Types: After expanding the list, the new columns will likely be of type 'Any'. Click the data type icon and select Text to ensure the data is ready for analysis or loading back to Excel.

Common Mistakes

One of the most frequent errors is confusing Text.Split with Text.SplitAny. The Text.Split function treats the delimiter as one single unit. For example, if you tell it to split by "|,", it will only split when it sees that exact sequence of two characters. If your data has a comma OR a pipe, it will fail to split. Text.SplitAny (or the Splitter.SplitTextByAnyDelimiter logic) treats every character in your list as an individual trigger for a split.

Another mistake is forgetting to handle whitespace. If your data looks like "Apple, Orange ; Banana", splitting by comma and semicolon will leave you with " Orange " (with leading and trailing spaces). You must follow your split step with a Transform > Trim operation to remove these invisible characters that cause lookup errors later.

Users also frequently encounter errors when the delimiter list contains special characters that M might interpret differently, such as quotes or backslashes. Always ensure that if you are including a double quote as a delimiter, you escape it by using two double quotes in your formula (e.g., "").

Tips

To keep your Power Query steps clean, avoid creating five separate "Split Column" steps for five different delimiters. This creates a heavy dependency chain that slows down refresh times. Using a single SplitTextByAnyDelimiter or Text.SplitAny step is significantly more performant because Power Query only has to scan the text string once per row.

If you are working with extremely large datasets, consider using the Transform menu instead of the Add Column menu. Using Transform modifies the existing column in place, which uses less memory than creating a brand-new column and then deleting the old one.

When expanding lists, always check your row count. If you expand a list into new rows, your total row count will increase. If you have 1,000 rows and each row splits into 3 items, you will end up with 3,000 rows. Ensure your subsequent steps (like Group By or Sum) account for this duplication of data.

Troubleshooting

If your formula returns an Expression.Error, the first thing to check is your syntax. M is case-sensitive. text.splitany will fail; it must be Text.SplitAny. Ensure all function names and column names match the casing in your query exactly.

If the split is not occurring at all, check for "hidden" characters. Sometimes data copied from web sources or PDF files contains non-breaking spaces or special Unicode characters that look like spaces or commas but are not. To fix this, try using the Replace Values feature to replace the problematic character with a standard one before running your split function.

If you receive an error stating that a value cannot be converted to a List, it means the function is being applied to a cell that contains a null value or a non-text value (like a number). You can resolve this by right-clicking the column and selecting Replace Errors or Replace Values (replacing null with an empty string "") before the split step.

Deep Dive: Splitter vs. Text Functions

Understanding the distinction between Splitter.SplitTextByAnyDelimiter and Text.SplitAny is vital for advanced data modeling. The Splitter functions are "higher-order functions." This means they don't return the split text immediately; instead, they return a function that can then be applied to a whole table. This is why you see them used inside Table.SplitColumn. This approach is much more powerful when you want to split a column into a specific number of new columns automatically.

On the other hand, Text.SplitAny is a direct text manipulation function. It is best used in a Custom Column when you want to create a List object within a single cell. If your goal is to simply clean up a column and turn it into multiple columns, the Table.SplitColumn method using the Splitter object is the professional standard for writing efficient M code.

Frequently Asked Questions

Can I split by a multi-character delimiter like " -- "?

If you use Text.SplitAny, it will split by every individual character (the space, the dash, and the other space). To split by the exact sequence " -- ", you must use Text.Split, which treats the entire string as one delimiter.

How do I handle null values during a split?

A null value will cause most split functions to return an error. Before splitting, use the Transform > Replace Values option to change null to an empty string, or use an if [Column] <> null then ... else null statement in your custom formula.

Will splitting a column change my original data?

If you use the Add Column tab, your original data remains untouched in the first column. If you use the Transform tab or the Split Column button in the ribbon, the original column is replaced by the new split columns.

Can I split by a delimiter that is a number?

Yes, but you must first ensure the column is set to the Text data type. Power Query cannot perform text splitting operations on columns formatted as Integers or Decimals.

Why does my split result in empty columns?

This usually happens if you have consecutive delimiters (e.g., "Apple,,Orange"). The function sees the second comma as a separator between two empty values. You can fix this by using Transform > Trim or by filtering out empty rows after the split.