REPLACE
A text with a number of its characters, from a position, replaced by another text.
Group: Text. Compatible with DAX.
Syntax
REPLACE ( <old_text>, <start_num>, <num_chars>, <new_text> )
| Parameter | Type | Description |
|---|---|---|
old_text | Text | The text to change. |
start_num | Whole number | Where the replaced part begins: 1 is the text's first character. |
num_chars | Whole number | How many characters to take out; 0 only inserts. |
new_text | Text | What goes in their place. |
Returns
Text. The text with those characters replaced.
Remarks
- REPLACE works by position. To replace by content, wherever a text occurs, use
SUBSTITUTE. - With 0 characters the new text is inserted; with empty new text the characters are removed. A start past the end adds the new text at the end.
- A start below 1, or a negative number of characters, is an error.
- When old_text and new_text are both blank the result is BLANK; a blank old_text with a new_text gives the new text.
Examples
Replacing, inserting, removing
EVALUATE
ROW (
"Replace", REPLACE ( "2026-11", 5, 1, "/" ),
"Insert", REPLACE ( "abc", 2, 0, "X" ),
"Remove", REPLACE ( "abcdef", 2, 3, "" ),
"At the end", REPLACE ( "abc", 10, 2, "X" )
)
| Replace | Insert | Remove | At the end |
|---|---|---|---|
| 2026/11 | aXbc | aef | abcX |
A number's digits
The number becomes text first.
EVALUATE
ROW ( "Year", REPLACE ( 2026, 3, 2, "30" ) )
| Year |
|---|
| 2030 |
Related functions
SUBSTITUTE, MID, LEFT, RIGHT.