Text.Remove deletes every occurrence of specified characters from a text value, returning the remaining characters in their original order. It is a fast way to strip punctuation, symbols, spaces, or any unwanted characters from a column without writing a custom function. The function takes two arguments: the text to clean and the character(s) to remove. For example, Text.Remove("A-123", "-") returns "A123". You can remove multiple characters at once by listing them in a single string, such as Text.Remove("Hello, world!", ", !") which returns "Helloworld". The characters are removed individually, not as a sequence, so order in the removal string does not matter. Text.Remove is case-sensitive only in the sense that it removes exact characters; it does not change case. It works on any text value and is available in Power Query for Excel, Power BI, and other Microsoft products that use the M engine. Before you start, you need a query with a text column and basic familiarity with the Power Query Editor. No special permissions or add-ins are required.

What You'll Need

  • Access to Power Query Editor (in Excel: Data > Get & Transform Data > Launch Power Query Editor; in Power BI: Transform data).
  • A query loaded with at least one text column you want to clean.
  • Basic understanding of adding a custom column or editing an existing step.

Step-by-Step

  1. Open the Power Query Editor. In Excel, go to the Data tab and click Launch Power Query Editor (or Get Data to import first). In Power BI Desktop, click Transform data on the Home ribbon. The exact label can vary slightly by version, but the editor is the same.
  2. Select the query and column. In the Queries pane on the left, click the query that contains your text column. Then click the column header to select it. If you want to create a new column instead of modifying the existing one, you can skip selecting the column and use Add Column > Custom Column later.
  3. Add a custom column (recommended). Go to the Add Column tab and click Custom Column. In the dialog, give the new column a name, such as "Cleaned Text". In the formula box, type Text.Remove([YourColumnName], "characters"), replacing [YourColumnName] with the actual column name (use the square brackets) and "characters" with the characters you want to remove. For example, to remove hyphens and spaces from a column named "Phone", use Text.Remove([Phone], "- "). Click OK.
  4. Alternatively, edit the existing column. If you prefer to modify the original column, right-click the column header and choose Replace Values, but that only replaces a specific substring. For character removal, you need a custom step. You can also use the formula bar: select the column, then in the formula bar prepend Text.Remove( and append , "characters") to the existing expression. This is more advanced and risks breaking the step if not done carefully.
  5. Check the result. After adding the custom column, scroll right to see the new column. Verify that the unwanted characters are gone and the remaining text looks correct. If you see errors, check the column name and that the characters are enclosed in double quotes.
  6. Remove the original column if desired. Right-click the original column header and choose Remove. This keeps your query tidy. You can also reorder columns by dragging.
  7. Close and load. When satisfied, click Close & Load (Excel) or Close & Apply (Power BI) to apply the changes to your worksheet or data model.

Common Mistakes

  • Forgetting to enclose characters in double quotes. The second argument must be a text string. Using Text.Remove([Column], -) without quotes will cause an error.
  • Using a list instead of a string. Text.Remove expects a single text value for the characters to remove, not a list. To remove multiple characters, put them all in one string, e.g., "-,.".
  • Assuming it removes substrings. Text.Remove removes individual characters, not sequences. To remove a specific word or pattern, use Text.Replace or Text.Select instead.
  • Case sensitivity confusion. Text.Remove is case-sensitive: removing "a" will not remove "A". If you need case-insensitive removal, you must handle both cases or use a different approach.
  • Not accounting for null values. If the column contains nulls, Text.Remove will return null for those rows. You may want to wrap it with if [Column] = null then null else Text.Remove([Column], "...") or use Text.Remove([Column] ?? "", "...") to treat null as empty.

Tips

  • To remove all non-alphanumeric characters, use Text.Remove([Column], Text.ToList("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")) but note that Text.Remove expects a string, so you would need to build a string of all characters. A simpler way is to use Text.Select([Column], {"a".."z", "A".."Z", "0".."9"}) to keep only letters and digits.
  • If you need to remove characters based on a pattern (like all punctuation), consider using Text.Select with a list of allowed characters, which is often easier.
  • Use the formula bar to experiment: you can see the M code for each step and edit it directly.
  • When removing spaces, remember that Text.Remove removes all spaces, including those between words. If you only want to trim leading/trailing spaces, use Text.Trim instead.
  • Combine Text.Remove with Text.Trim to clean up extra spaces after removing characters.

Troubleshooting

  • Error: "We cannot apply operator & to types Text and Number" – This usually means the column contains numbers, not text. Convert the column to text first (right-click column header > Change Type > Text).
  • Nothing is removed. Check that the characters you specified exactly match those in the text. For example, a non-breaking space (char 160) looks like a regular space but is different. Use Text.Remove([Column], Character.FromNumber(160)) to remove it.
  • Unexpected results with special characters. Some characters like quotes or backslashes need escaping in M code. For example, to remove a double quote, use """" (four double quotes) in the string. Alternatively, use Character.FromNumber(34).
  • Performance issues with large datasets. Text.Remove is generally fast, but if you are working with millions of rows, consider doing the cleaning in the source system or using more efficient transformations.
  • Null values causing errors. As mentioned, handle nulls explicitly. Use try Text.Remove([Column], "...") otherwise null to avoid errors.

Frequently Asked Questions

Can Text.Remove remove multiple different characters at once?

Yes, list all characters in a single string, e.g., Text.Remove([Column], "abc123") removes any 'a', 'b', 'c', '1', '2', or '3'.

Does Text.Remove work on numbers?

No, it requires a text value. Convert numbers to text first using Text.From or by changing the column type.

How do I remove a specific word instead of characters?

Use Text.Replace or Text.RemoveRange to remove a substring by position. Text.Remove only removes individual characters.

Is Text.Remove case-sensitive?

Yes, it distinguishes between uppercase and lowercase. To remove both, include both cases in the removal string.

What happens if the character is not found?

Text.Remove simply returns the original text unchanged.

Can I use Text.Remove on a column with mixed data types?

No, the column must be text. Convert it to text type first.