Downloads
DAXTextIntermediate

REPLACE

Replaces part of a text value, starting at a position and covering a set number of characters.

Syntax
REPLACE(<old_text>, <start_num>, <num_chars>, <new_text>)

Returns: Text (a scalar).

What it does

REPLACE overwrites part of a text value by position. You say where to start, how many characters to cover, and what to put there. This differs from SUBSTITUTE, which finds the text by content. REPLACE is the right tool for fixed-width codes, such as masking the first digits of an account number or swapping one segment of a code.

Syntax and arguments

Example

Vendor bank account numbers are shown on screens for review, but the first eight digits must be hidden.

Masked Account =
REPLACE(Vendors[BankAccount], 1, 8, "********")

A number of twelve digits shows the last four in full and the first eight as asterisks. This is a display mask, so restrict the screens that show it, and do not treat it as a security control.

Example: a second, different use

Change the year segment of a fixed-format document reference from 2025 to 2026 for a rollover:

New Reference = REPLACE(Documents[Reference], 4, 4, "2026")

If the reference is "INV2025-0142", the year at positions 4 to 7 becomes 2026. The rest of the reference is kept unchanged.

Things to watch

In business terms

REPLACE is used for masking account numbers on screens, rolling fixed-format references to a new year and cleaning codes with a known layout. Auditors ask for masking when personal or bank data appears on review screens, so a clear rule is useful.

Related functions

All DAX functions · View as Markdown · DAX fundamentals