Text.RemoveRange removes a specified number of characters from a text value, starting at a given position. In Power Query (the data transformation engine in Excel and Power BI), the M function is written as Text.RemoveRange(text as nullable text, offset as number, optional count as nullable number) as nullable text. It returns the original text with the characters between offset and offset+count removed. If you omit count, it removes everything from offset to the end of the string. You need a text column or value to work on, and you need to be in the Power Query Editor (or writing an M query directly).

What You'll Need

  • Excel (any recent desktop version) or Power BI Desktop with the Power Query Editor available.
  • A table or text value loaded into Power Query. This can be a column of text, a parameter, or a literal string.
  • Basic familiarity with the Power Query Editor: the ribbon, the formula bar, and the Applied Steps pane.
  • A clear idea of the character positions you want to remove. Positions are zero-based: the first character is at offset 0, the second at 1, and so on.

Step-by-Step

  1. Load your data into Power Query. In Excel, select your table and go to Data > From Table/Range. In Power BI Desktop, use Home > Transform data to open the Power Query Editor. The exact labels can differ slightly by version and platform, but the Editor itself is the same.
  2. Select the text column you want to change. Click the column header in the data preview. This ensures any step you add applies to that column.
  3. Add a custom column (recommended for a first test). Go to Add Column > Custom Column. Give it a name such as "Trimmed". In the formula box, type a formula that calls Text.RemoveRange on the existing column. For example, if your column is named Code and you want to remove three characters starting at position 2, enter: Text.RemoveRange([Code], 2, 3) Click OK. A new column appears with the result, leaving the original intact.
  4. Check the result in the preview. Scroll the new column and compare a few rows against the original. Confirm the characters you expected are gone and nothing else changed. If the preview shows errors, see Troubleshooting below.
  5. Apply the change to the original column when you are confident. Select the original column, then use Transform > Replace Values or, more directly, edit the step in the formula bar. A clean approach is to right-click the column header and choose Replace Values with the full text, but that is cumbersome for many rows. Instead, add a step manually: with the column selected, go to Home > Advanced Editor is not needed; simply use Add Column > Custom Column as above, then remove the original column and rename the new one. This keeps the logic transparent and reversible.
  6. Handle nulls and blanks deliberately. Text.RemoveRange returns null if the input is null. If you want blanks to stay blank and nulls to become empty text, wrap the call: if [Code] = null then null else Text.RemoveRange([Code], 2, 3). Decide this before you remove the original column.
  7. Rename and reorder columns if needed. Right-click the new column header to rename it to match the original, then remove the old column. Use the Applied Steps pane to confirm each step is what you intended.
  8. Load the result. In Excel, go to Home > Close & Load > Close & Load To and choose where the table goes. In Power BI Desktop, use Home > Close & Apply. The transformed text is now in your model or worksheet.

Common Mistakes

  • Counting from 1 instead of 0. Power Query offsets are zero-based. To remove the first character, use offset 0, not 1. To remove the third character, use offset 2.
  • Confusing offset with length. The second argument is where removal starts; the third is how many characters to remove. Text.RemoveRange("ABCDE", 1, 2) returns "ADE", not "AB".
  • Forgetting that omitting count removes the rest of the string. Text.RemoveRange("ABCDE", 2) returns "AB". If you only meant to remove a few characters, always supply count.
  • Assuming it works on numbers or dates. The function expects text. Convert first with or change the column type before calling it.
  • Ignoring nulls. A null input returns null, which can look like a silent failure if you expected an empty string. Handle nulls explicitly.
  • Editing the wrong step. Changes in the Applied Steps pane apply from that step forward. If you edit an early step, later steps may break. Prefer adding a new step rather than rewriting an old one.

Tips

  • Use Text.Length to check how long a string is before choosing an offset. For example, Text.Length([Code]) in a temporary custom column tells you the maximum safe offset.
  • When removing a fixed prefix, Text.RemoveRange([Code], 0, 3) is clearer than a series of Replace Values steps and survives changes in the data.
  • For removing a suffix of unknown length, combine with Text.Length: Text.RemoveRange([Code], Text.Length([Code]) - 2, 2) removes the last two characters.
  • Keep the original column until you have verified the new one. Removing it early makes it harder to compare results.
  • If you need to remove characters by pattern rather than position, Text.RemoveRange is the wrong tool. Use Text.Select or Text.Replace instead.
  • Document your custom column formula in the column name or a comment step so future editors understand the offset logic.

Troubleshooting

If the new column shows Error, click the error cell to see the message. The most common cause is passing a non-text value or an offset larger than the string length. Check the column type first: select the column and confirm it is type Text in the Transform tab. If it is type Any or Number, change it to Text before calling Text.RemoveRange.

If the result is blank when you expected text, check whether the input was null. Null propagates through the function. Add a null check as shown in the steps.

If the characters removed are not the ones you expected, recount the offset. Remember that spaces, punctuation, and hidden characters all count as characters. Use a temporary column with Text.Length and Text.PositionOf to inspect the string.

If the step worked in the preview but fails after loading, check that the column name has not changed upstream. Renaming a column in an earlier step breaks formulas that refer to the old name. Use the Advanced Editor to inspect the step and fix the reference.

If Power Query refuses the formula entirely, verify the function name spelling and argument count. The function takes two or three arguments; a fourth argument or a missing comma will produce a syntax error.

Frequently Asked Questions

Is Text.RemoveRange zero-based or one-based?

Zero-based. The first character is at offset 0. To remove the first character, use offset 0 and count 1.

What happens if I omit the count argument?

Power Query removes everything from the offset to the end of the string. For example, Text.RemoveRange("ABCDE", 2) returns "AB".

Can I remove characters from the end of a string?

Yes. Calculate the starting offset from the string length. To remove the last two characters, use Text.RemoveRange([Column], Text.Length([Column]) - 2, 2).

Does Text.RemoveRange work on numbers?

No. It expects text. Convert the value first with Text.From or change the column type to Text.

What does it return for a null input?

It returns null. If you need an empty string instead, wrap the call in an if expression that checks for null.

Can I use it inside a custom column formula?

Yes. That is the most common use. Add a custom column and call Text.RemoveRange on the column reference, for example Text.RemoveRange([Code], 2, 3).