REPLACE Function (DAX)

How does the REPLACE function (DAX) work?

The REPLACE function (DAX) replaces part of a text string, based on the number of characters you specify, with a different text string.

REPLACE Formula Syntax

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

How do you use the REPLACE function?

Whereas Microsoft Excel has different functions for use with single-byte and double-byte character languages, DAX uses Unicode and therefore stores all characters at the same length.

This DAX function may return different results when used in a model that is deployed and then queried in DirectQuery mode.

Related Blog Posts

Related Support Forum Posts

Replacing Substitute from Excel
Replace USERPRINCIPLE NAME with custom name
Replace USERPRINCIPLE NAME with custom name

Considerations when using the REPLACE function

If the argument, num_chars, is a blank or is a reference to a column that evaluates to a blank, then new_text is inserted at the position start_num, without replacing any characters. This is the same behavior as in Excel.

DAX REPLACE function is similar to DAX SUBSTITUTE function.

  • You can use REPLACE function, if you want to replace any text of variable length that occurs at a specific position in a text string.
  • You can use SUBSTITUTE function, if you want to replace specific text in a text string.

Related Video Tutorials

Formula examples using the REPLACE function

= REPLACE(‘New Products'[Product Code],1,2,”OB”)

Related DAX Functions

Related Course Modules

Ultimate-Beginners-Guide-To-PowerBI

DOWNLOAD

To access our comprehensive DAX formula reference guide just insert your email address below. The resource will download immediately and we’ll also email it to you.