Text.Replace

Text

Replaces all occurrences of a substring within a text value.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Text.Replace(text as nullable text, old as text, new as text) as nullable text

Parameters

NameTypeRequiredDescription
texttextYesThe original text value.
oldtextYesThe substring to find and replace.
newtextYesThe replacement text.

Return Value

textThe text with all occurrences of the old substring replaced by the new substring.

Remarks

Text.Replace finds all occurrences of a substring and replaces them with a new value. The comparison is case-sensitive. To remove a substring entirely, pass an empty string "" as the replacement.

For replacing values at the table level (across entire columns), use Table.ReplaceValue with Replacer.ReplaceText instead.

Examples

Example 1: Clean phone numbers

Table.AddColumn(
    Table.SelectColumns(Table.FirstN(Employees, 3), {"Phone"}),
    "Cleaned", each Text.Replace([Phone], "-", ""), type text
)
Result
Phone
Cleaned
1(555) 123-4567(555) 1234567
2(555) 234-5678(555) 2345678
3(555) 345-6789(555) 3456789

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks