String Functions

Top Previous Topic Next Topic  Print this topic

String Functions perform basic operations on strings obtained from various data sources. The supported string functions are listed below:

 

1. Concatenate - concatenates two or more input values into a resulting string.

The following example returns the concatenated values for FIRST_NAME and LAST_NAME with a comma between them.

Concatenate

 

Note: To add more input values, right click on the function and select Add Parameter.

 

OUTPUT:

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ns:root xmlns:ns="http://www.tempuri.org/XML">

       <ns:emp first-name="John" last-name="Brown" full-name="John,Brown"/>

       <ns:emp first-name="Mary" last-name="Jane" full-name="Mary,Jane"/>

       <ns:emp first-name="Arthur" last-name="Clark" full-name="Arthur,Clark"/>

</ns:root>

 

 

 

2. Substring - returns a substring from an input value. This function must have three parameters named string, pos and size.

The first parameter, string, is the entire input string that you would like shortened, pos is the position of the character that will start your substring (zero is the first character position in the input string), and size is the number of characters to output. The following sample returns the initials of last name and first name for every employee.

 

Substring

 

 

Note. This sample can be found in Substring.dax from Samples\Job Samples folder.

 

OUTPUT:

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ns:root xmlns:ns="http://www.tempuri.org/XML">

       <ns:emp first-name="John" last-name="Brown" initials="JB"/>

       <ns:emp first-name="Mary" last-name="Jane" initials="MJ"/>

       <ns:emp first-name="Arthur" last-name="Clark" initials="AC"/>

</ns:root>

 

 

 

3. Contains - returns "true" if a string obtained from an input value contains another string. This function must have two parameters named content and substring.

The following sample returns "true" if the department name contains "Develop".

Contains

 

Note. This sample can be found in Contains.dax from Samples\Job Samples folder.

 

OUTPUT:

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ns:root xmlns:ns="http://www.tempuri.org/XML">

       <ns:hist department="Accounting" contains-Develop="false"/>

       <ns:hist department="Sales" contains-Develop="false"/>

       <ns:hist department="Development" contains-Develop="true"/>

</ns:root>

 

 

 

4. Starts-With and Ends-With functions return "true" if a string obtained from an input value starts-with (or ends-with) another string. This function must have two parameters named string and substring.

The following sample returns "true" if each DATE_MODIFIED starts with a "7" (for July).

Starts-With

 

Note. This sample can be found in StartsWith.dax from Samples\Job Samples folder.  

 

OUTPUT:

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ns:root xmlns:ns="http://www.tempuri.org/XML">

       <ns:hist date-modified="2009-07-01T00:00:00Z" modified_in_July="true"/>

       <ns:hist date-modified="2009-07-22T00:00:00Z" modified_in_July="true"/>

       <ns:hist date-modified="2009-07-16T00:00:00Z" modified_in_July="true"/>

       <ns:hist date-modified="2009-07-22T00:00:00Z" modified_in_July="true"/>

       <ns:hist date-modified="2009-07-16T00:00:00Z" modified_in_July="true"/>

       <ns:hist date-modified="2009-07-17T00:00:00Z" modified_in_July="true"/>

       <ns:hist date-modified="2009-08-27T00:00:00Z" modified_in_July="false"/>

</ns:root>