Power Query Problems

How to Remove Text After a Specific Word in Power Query

John WilsonJohn Wilson Nov 11, 2026 868 views

Question details

The user needs to extract text from a string up to the word "NUL" and discard the remaining characters while keeping "NUL" in the final result.

How to Remove Everything After "NUL" in Power Query
Product
Excel Power Query
Device & OS
not provided
Scenario
Cleaning and formatting data strings in Power Query.
Observed behavior
The goal is to truncate strings after a specific substring, for example, converting "1287JLPO-NUL-00-000-00000" to "1287JLPO-NUL".
Before you start

Ensure your dataset is loaded into the Power Query Editor and identify the exact column containing the strings you want to modify. Note that Power Query is case-sensitive, so confirm the exact capitalization of your target word.

Solution 1Recommended

Use Text.BeforeDelimiter and Append Text in M Code

This is the most efficient and direct method using Power Query's custom column formula.

The standard extraction tool removes the delimiter itself. By using M code, you can extract the text before the delimiter and immediately concatenate the delimiter back onto the result string.

1
Add a Custom Column

In the Power Query Editor, navigate to the Add Column tab on the top ribbon and click on Custom Column.

2
Enter the M Code Formula

In the Custom Column dialog, enter the following formula: = Table.AddColumn(Source, "Before delimiter", each Text.BeforeDelimiter([String], "NUL") & "NUL"). Ensure you replace [String] with your actual column name.

3
Apply and Close

Click OK to save the column. The new column will display the truncated text while retaining the "NUL" string. You can now load the cleaned data.

Use Text.BeforeDelimiter and Append Text in M Code
Case Sensitivity: Remember that M code is strictly case-sensitive. Ensure that the delimiter "NUL" matches the exact casing found in your dataset.
Free Microsoft Office alternative

Looking for a Free and Powerful Spreadsheet Editor?

While Power Query is a feature specific to Microsoft Excel, WPS Office provides a lightweight, highly compatible, and free alternative for your daily spreadsheet and data processing needs. With advanced formulas, intuitive data cleaning tools, and familiar interfaces, you can seamlessly manage your data without hefty subscription fees.

  1. 1. Download and Install: Visit the WPS Official website to download the free WPS Office suite.
  2. 2. Open Your Data File: Launch WPS Spreadsheets and open your .xlsx or .csv files seamlessly.
  3. 3. Use Text Formulas: Utilize built-in text functions like LEFT and SEARCH to clean and extract your data quickly without needing complex scripting languages.
100% compatible with Microsoft Excel formats (.xlsx, .xls, .csv).Free to use with a familiar, easy-to-navigate user interface.Built-in advanced text manipulation formulas (like LEFT, FIND, and REPLACE) to handle complex text extraction easily.Lightweight installation that runs smoothly on almost any device.
microsoft office alternative - wps office

Frequently Asked Questions

Does Power Query's Text.BeforeDelimiter keep the delimiter itself?

No, by default, the Text.BeforeDelimiter function removes the specified delimiter along with the trailing text. To retain the delimiter, you must concatenate it back to the result using the ampersand (&) operator.

Is Power Query M code case-sensitive when searching for text?

Yes, M code is strictly case-sensitive. Searching for "NUL" will not match "nul" or "Nul". Ensure your delimiter matches the exact capitalization in your dataset.

How can I accomplish this using standard Excel or WPS Spreadsheets formulas instead of Power Query?

You can use a combination of standard spreadsheet functions. Assuming your text is in cell A1, you can use the formula =LEFT(A1, SEARCH("NUL", A1) + 2) to extract the text and keep "NUL".