The Replace Function [DAX’s Functions!]
Contents
The Replace function in DAX is a Power BI text function that you use to replace part of a text string with a different text string.
It is relatively straightforward to use and appropriate for DAX beginners to be using.
Syntax & Return Value of Replace Function
Replace Function Syntax:
Old text: | A reference to a text column or a string of text containing the characters you want to replace. |
Start number: | The position of the first character in the old text that you want to replace with new text. |
Number of characters: | The total number of characters you want to change |
New text: | The replacement text for the characters in the old text that were specified. |
Replace Function Return Value:
The return value of the replace function in DAX is a text string.
Simple Example Using the Replace Function.
Lets start with a very simple example of using the replace function.
We would like to replace the string “DEF” with “EEE.”
First, choose New Column.
Next, as shown below, type the Replace formula in the formula bar.
This will give you the result below.
A more realistic example might be that we want to change an old text string (SO) for a new text string (Sales Order) in the calculated column calculations below.
The outcome of the replace function in DAX is shown below.
PRO-TIP
Use the SUBSTITUTE function to replace specific text in a text string of variable length
Use the REPLACE function to replace text of variable length that occurs in a specific location in a text string.
Conclusion
Remember that replace allows you to replace a portion of a text string with another text string starting at a certain spot.
Other DAX Articles