<!-- https://learnsql.cpetoday.com/functions/m/text-replace -->
# Text.Replace

Language: Power Query M
Category: Text
Syntax: Text.Replace(text as nullable text, old as text, new as text) as nullable text
Summary: Replaces every occurrence of one piece of text with another.
Returns: The text with each match replaced, or null when the input is null.
Level: Beginner
Related: Text.Remove, Text.Clean, Text.Trim, Number.FromText, Text.Select

## What it does
Text.Replace swaps every match of one piece of text for another. Replacing with an empty text removes the piece entirely. It is the usual first step when an amount arrives as text with commas or currency signs in it, because the text has to be cleaned before it can become a number.
## Syntax and arguments
- text: the value to change.
- old: the text to find. Every occurrence is replaced.
- new: the text to put in its place. Use "" to delete the match.
## Example
A bank export shows amounts as text with thousands separators and a dollar sign. The team strips the extra characters, then converts the result to a number.

```powerquery
let
    Raw = "$1,234.50",
    NoSymbol = Text.Replace(Raw, "$", ""),
    NoComma = Text.Replace(NoSymbol, ",", ""),
    Amount = Number.FromText(NoComma, "en-US")
in
    Amount
```

NoComma is "1234.50" and Amount is the number 1234.5. Each step is shown so a reviewer can see exactly what changed.
## Example: a second, different use
Replace the dashes in a bank reference with nothing so two references written in different formats can be compared: "INV-1043" becomes "INV1043".
## Things to watch
- Text.Replace is case sensitive. Replacing "usd" does not change "USD".
- It replaces every match, not just the first. That is usually what you want for characters, but check it on a value with a repeated pattern.
- To remove several different characters in one step, Text.Remove is shorter.
- Null in gives null out.
## In business terms
Amounts, phone numbers and reference codes exported as text need cleaning before any total can be made. Text.Replace followed by a number conversion is how a bank or processor feed becomes a column that sums correctly.
