DAX Text - REPLACE function



Description

Replaces part of a text string, based on the number of characters you specify, with a different text string.

Syntax

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

Parameters

Sr.No. Parameter & Description
1

old_text

The string of text that contains the characters you want to replace, or a reference to a column that contains text.

2

start_num

The starting position in the old_text that you want to replace with new_text.

3

num_chars

The number of characters that you want to replace.

4

new_text

The replacement text for the specified characters in old_text.

Return Value

A text string.

Remarks

DAX uses Unicode and therefore stores all characters as the same length.

Note − 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.

Example

= REPLACE([Product],1,2, [No. of Units]) 

This returns a calculated column with the first two characters of the Product in a row replaced with the value No. of Units in the same row.

dax_functions_text.htm
Advertisements