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
<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
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”)