Smart Systems for Home

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

Splitter.SplitTextByWhitespace in Power Query Explained

· 6 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

The Splitter.SplitTextByWhitespace function in Power Query is used to divide a single string of text into a list of separate items based on where spaces, tabs, or line breaks occur. This is the most efficient way to handle data where the number of spaces between words varies, as it treats multiple consecutive whitespace characters as a single delimiter rather than creating empty columns for every single space found. To use it, you typically wrap it inside the Table.SplitColumn function or use it within a custom column formula to transform a text string into a list.

What You'll Need

  • Microsoft Excel (with Power Query/Get & Transform) or Power BI Desktop.
  • A dataset containing a text column with inconsistent spacing or a need to isolate words/values separated by whitespace.
  • Basic familiarity with the Power Query Editor interface.

Step-by-Step

  1. Load Your Data: Open Power BI Desktop or Excel. Go to the Data tab (Excel) or Home tab (Power BI) and select Get Data to import your source file, table, or database. Once the data is loaded, click Transform Data to open the Power Query Editor window.
  2. Identify the Target Column: Locate the column containing the text you wish to split. For example, a column named "Full Name" that contains first, middle, and last names separated by varying numbers of spaces.
  3. Access the Split Column Feature: Right-click the header of the target column. Navigate to Split Column > By Delimiter. (Note: While you can write the M code manually, using the UI first generates the correct function call).
  4. Configure the Split Settings: In the dialog box that appears, select "Space" from the delimiter dropdown menu. Under the "Split at" section, ensure you select "Each occurrence of the delimiter."
  5. Handle Multiple Spaces: To specifically trigger the behavior of Splitter.SplitTextByWhitespace, you must ensure that the option to treat consecutive delimiters as one is enabled. In the UI, this is often handled automatically when choosing "Space" in newer versions, but the underlying M code will generate Splitter.SplitTextByWhitespace if the system detects the need to ignore empty results from multiple spaces.
  6. Review the Generated M Code: To see the function in action, look at the Formula Bar at the top of the screen. You will see a formula resembling = Table.SplitColumn(Source, "ColumnName", Splitter.SplitTextByWhitespace({}), {"Column1", "Column2"}). The Splitter.SplitTextByWhitespace({}) part is the engine doing the work.
  7. Using as a Custom Column: If you prefer to keep the original column and create a list in a new column, go to the Add Column tab > Custom Column. In the formula box, enter Splitter.SplitTextByWhitespace({})([YourColumnName]). This will result in a "List" object in each cell rather than splitting the table into multiple columns.
  8. Expanding the List: If you used the Custom Column method, click the small expand icon (two arrows pointing away from each other) at the top right of the new column header. Choose "Expand to New Rows" to normalize the data or "Extract Values" to join them back with a different delimiter.
  9. Finalize Data Types: After splitting, Power Query usually assigns the "Any" data type to the new columns. Select the new columns, right-click, and choose Change Type > Text to ensure data integrity.

Common Mistakes

One of the most frequent errors is confusing Splitter.SplitTextByEachDelimiter with Splitter.SplitTextByWhitespace. If you use a standard space delimiter, Power Query will create a new column for every single space it encounters. If a user accidentally typed two spaces between a first and last name, a standard split will result in a blank column in the middle of your data. Splitter.SplitTextByWhitespace prevents this by treating all contiguous whitespace as a single break point.

Another common mistake is forgetting that this function is case-sensitive in terms of how it is typed in the Advanced Editor. M code is a functional language; typing splitter.splittextbywhitespace (lowercase) will result in a "Token Literal expected" or "Expression.Error: The name... wasn't recognized" error. Always maintain the exact PascalCase capitalization.

Users also often fail to trim their data before splitting. While the whitespace splitter handles internal gaps well, leading or trailing spaces can sometimes result in unexpected empty elements at the start or end of the resulting list. It is best practice to use the Transform > Trim feature on the column before applying the split function.

Tips

For advanced users, the Splitter.SplitTextByWhitespace({}) function is incredibly powerful when combined with Table.ExpandListColumn. Instead of splitting a column into a fixed number of columns (like Column 1, Column 2, Column 3), splitting into a list and then expanding to new rows allows you to handle strings with an unpredictable number of words. This is essential for analyzing tags, keywords, or unstructured notes where one row might have two words and another might have twenty.

If you are working with very large datasets, avoid creating too many split columns in a single step. Every split creates a new step in the Power Query applied steps list, which can slow down the refresh rate. If you find yourself splitting the same column multiple times, consider writing a single custom M function to handle the logic in one pass.

When using the Custom Column approach, you can wrap the splitter in a List.Select function to remove any nulls or empty strings that might have slipped through, ensuring your final dataset is clean and ready for analysis without needing further filtering steps.

Troubleshooting

If the function does not seem to be splitting the text, the first thing to check is the nature of the "whitespace." Not all spaces are created equal. Some data imported from the web contains "Non-Breaking Spaces" (ASCII 160) instead of standard spaces (ASCII 32). Splitter.SplitTextByWhitespace may not recognize these as standard whitespace. To fix this, go to Transform > Replace Values, find the non-breaking space (you can copy it from a cell), and replace it with a standard space before running the split.

If you receive an error stating that the function is not recognized, check your Power Query version. While this function is standard in most modern versions of Excel and Power BI, extremely old versions of Power Query (pre-2016) may require different syntax. Ensure your software is updated to the latest version.

If your columns are splitting into a massive number of columns (e.g., Column 1 through Column 100), it means you likely used "Split by Delimiter" with a standard space instead of the whitespace splitter. To fix this, delete the split step from the Applied Steps pane and re-apply it, ensuring you are using the whitespace logic or manually editing the M code in the formula bar to use Splitter.SplitTextByWhitespace({}).

Frequently Asked Questions

Does this function handle tabs and carriage returns?

Yes, the whitespace splitter is designed to recognize any character that qualifies as whitespace, including tabs (\t), carriage returns (\r), and line feeds (\n), treating them all as delimiters.

Can I specify how many columns to split into?

The function itself creates a list of all possible splits. However, when used within Table.SplitColumn, you can define the number of resulting columns. If the text contains more words than the columns you defined, the remaining text stays in the last column.

Is there a difference between Splitter.SplitTextByWhitespace and splitting by a space character?

Yes. Splitting by a space character treats every single space as a delimiter. Splitting by whitespace treats a sequence of one or more whitespace characters as a single delimiter, preventing empty columns.

How do I split text by whitespace and keep the original column?

Instead of using the "Split Column" menu (which replaces the original), use "Add Column" > "Custom Column" and enter the formula Splitter.SplitTextByWhitespace({})([ColumnName]). This creates a new list column while preserving the source.

Can I use this function to split text by a comma and a space?

No, Splitter.SplitTextByWhitespace only looks for whitespace. If you need to split by a comma and a space, you should use Splitter.SplitTextByDelimiter(", ") or perform a "Replace Values" to turn commas into spaces first.