---
schema_version: "1"
id: a4a02616dca3a8496f712d6247ef355f23d5446967134d02fa4fd0ccb86d6a77
title: String Functions for Formulas
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/analytics/264-0-0/bi_integrate_recipe_stringfunctions.md
canonical_url: https://help.salesforce.com/s/articleView?id=analytics.bi_integrate_recipe_stringfunctions.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: bd537ca930ea7fedf4a02373032453e482c068ea7f3561fa3874166dba8bc75c
description: In CRM Analytics, use string functions to create values based on other strings. For example, you can change the casing of text strings, concatenate values from multiple columns, and replace values. The arguments for string functions must be text strings or fields.
products:
  - CRM Analytics
  - Cross Cloud
release: "264"
---
# String Functions for Formulas

In CRM Analytics, use string functions to create values based on other strings. For example, you can change the casing of text strings, concatenate values from multiple columns, and replace values. The arguments for string functions must be text strings or fields.

## String Functions for Formulas

When you enter a formula, use the API name of the column in the expression, not the label. The parameters section is surrounded by parentheses. Also, text strings must be enclosed in single straight quotes (`'This is a string.'`).

For example, you can nest string functions in an expression to combine the sales territory and country into a column. Then you can apply title casing to the results. `title(concat(Sales_Territory, ' ',Country))`

You can use the following string functions in a formula expression.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:11.614401858304298%">
          <col style="width:17.18931475029036%">
          <col style="width:71.19628339140534%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d191127e55">String Function</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d191127e58">Description</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d191127e61">Syntax</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>char_length</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Returns the number of characters in the specified string. Leading and
              trailing whitespace characters are included in the length returned.</td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p>
                <code>char_length(<samp class="parmname">field</samp>)</code>
              </p>
              <p><samp class="parmname">field</samp>
                is the text (dimension) field or string to measure.</p>
              <p>Example: A
                point-of-service checkout tool generates receipts with a maximum number of
                characters. Evaluate your product names to see their
                length.</p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>char_length(product_name)</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>concat</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Returns a string by merging the values of the specified columns and input
              strings.</td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p>
                <code>concat(<samp class="parmname">field1</samp>,<samp class="parmname">field2</samp>,...<samp class="parmname">fieldN</samp>)</code>
              </p>
              <p><samp class="parmname">field1</samp>
                is the first text (dimension) field or string to include in the concatenated
                value.</p>
              <p><samp class="parmname">field2</samp> is the second text (dimension) field or
                string to include.</p>
              <p><samp class="parmname">fieldN</samp> is any number of extra text
                (dimension) fields or strings to include.</p>
              <p>Example: To create the full
                name, concatenate the first and last names with a space in between
                them.</p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>concat("OwnerId.FirstName",' ',"OwnerId.LastName")</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>endsWith</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Returns true if the specified string is found at the end of the column value.
              This function is only supported in <code>case</code>
              functions because it returns as a boolean.</td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p><code>ends_with(<samp class="parmname">fieldName</samp>,<samp class="parmname">literal</samp></code>)</p>
              <p><samp class="parmname">fieldName</samp>
                is the text (dimension) field to search.</p>
              <p style="margin-bottom:0;"><samp class="parmname">literal</samp> is
                the value to search for at the end of the field.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>instr</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Returns the (1-based) first location of the value 'searchString' in the
              specified 'field' column. Optionally, start the search at a different location
              with 'position', or return the location of a different searchString instance with
              'occurrence'. </td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p>
                <code>instr(<samp class="parmname">field</samp>,
                <samp class="parmname">searchString</samp>, [<samp class="parmname">position</samp>,
                [<samp class="parmname">occurrence</samp>]])</code>
              </p>
              <p><samp class="parmname">field</samp> is
                the text (dimension) field or string that is being evaluated to find the
                <samp class="parmname">searchString</samp>.
              </p>
              <p><samp class="parmname">searchString</samp> is
                the text (dimension) field or string that is being searched for in the
                <samp class="parmname">field</samp>.
              </p>
              <p><samp class="parmname">position</samp> is the start
                location in <samp class="parmname">field</samp> where the search begins. This parameter
                is optional. If you don't specify a position, the search begins at position
                1.</p>
              <p><samp class="parmname">occurrence</samp> is the specific instance of the
                <samp class="parmname">searchString</samp> to return. This parameter is optional. Use
                <samp class="parmname">position</samp>, too, if you use this parameter. If you don't
                specify a position, the search begins at position 1.
              </p>
              <p>Example: Evaluate a
                string for an exclamation
                point.</p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>instr('123!456!78!', !)
                            --The result is 4
                            
                            instr('123!456!8!', !, [4])
                            --The result is 7
                            
                            instr('123!456!8!', !, [4, [2]])
                            --The result is 9
                          </code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>lower</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Returns the string with all characters in lowercase. If the input string is
              null, then the result is null.</td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p>
                <code>lower(<samp class="parmname">field</samp>)</code>
              </p>
              <p><samp class="parmname">field</samp> is
                the text (dimension) field or string to convert to lowercase.</p>
              <p>Example: The
                Account.Industry column uses different casing for industries, like “Media” and
                “media.” To apply consistent casing to the columns values, convert them to
                lowercase.</p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>lower("Account.Industry")</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>ltrim</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Removes the specified substring from the beginning of a string. If no
              substring is provided, remove the leading space characters from a string.</td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p><code>ltrim(<samp class="parmname">field</samp>,<samp class="parmname">valueToBeRemoved</samp></code>)</p>
              <p><samp class="parmname">field</samp>
                is the text (dimension) field or string to remove the leading spaces or
                specified substring from.</p>
              <p><samp class="parmname">valueToBeRemoved</samp> is the
                value to remove from the string. This parameter is optional. If you don't
                specify a valueToBeRemoved, the transformation removes the leading
                spaces.</p>
              <p>Example: Trim the leading space characters from a
                string.</p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>ltrim('     5 Spaces Before')</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>replace</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Replaces a substring with another string. If any of the arguments are null,
              then the function returns null. This function is case-sensitive.</td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p>
                <code>replace(<samp class="parmname">field</samp>,<samp class="parmname">searchString</samp>,<samp class="parmname">replacementString</samp>)</code>
              </p>
              <p><samp class="parmname">string</samp>
                is the text (dimension) field or string that contains the substring to be
                replaced.</p>
              <p><samp class="parmname">searchString</samp> is the substring to replace.
                If searchString is an empty string, the function returns
                null.</p>
              <p><samp class="parmname">replacementString</samp> is the value that replaces
                the substring.</p>
              <div>
                <p>Example: Change the account name from “salesforce.com” to
                  “Salesforce” in the Account_Name
                  column.</p>
                <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>replace(Account_Name,'salesforce.com','Salesforce')</code></pre>
              </div>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>rtrim</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Removes the specified substring from the end of a string. If no substring is
              provided, remove the trailing space characters from the end of a string.</td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p><code>rtrim(<samp class="parmname">field</samp>,<samp class="parmname">valueToBeRemoved</samp></code>)</p>
              <p><samp class="parmname">field</samp>
                is the text (dimension) field or string to remove the trailing spaces or
                specified substring from.</p>
              <p><samp class="parmname">valueToBeRemoved</samp> is the
                value to remove from the string. This parameter is optional. If you don't
                specify a valueToBeRemoved, the transformation removes the trailing
                spaces.</p>
              <div>
                <p>Example: Trim the 2 trailing space characters from a
                  string.</p>
                <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>rtrim('2 Spaces After  ')</code></pre>
              </div>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>startsWith</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Returns true if the specified string is found at the beginning of the column
              value. This function is only supported in <code>case</code> functions because it returns as a boolean.</td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p><code>startsWith(<samp class="parmname">fieldName</samp>,<samp class="parmname">literal</samp></code>)</p>
              <p><samp class="parmname">fieldName</samp>
                is the text (dimension) field to search.</p>
              <p style="margin-bottom:0;"><samp class="parmname">literal</samp> is
                the value to search for at the beginning of the field.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>string</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Converts the date or number value to a string data type.</td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p>
                <code>string(<samp class="parmname">expression</samp>)</code>
              </p>
              <p style="margin-bottom:0;"><samp class="parmname">expression</samp>
                is the date or number (measure) field to convert.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>substr</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Returns characters from the string, starting at the specified position and of
              the specified length. Also called <code>substring</code>.</td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p>
                <code>substr(<samp class="parmname">field</samp>,<samp class="parmname">position</samp>,<samp class="parmname">len</samp>)</code>
              </p>
              <p><samp class="parmname">field</samp>
                is the text (dimension) field or string to extract the substring
                from.</p>
              <p><samp class="parmname">position</samp> is the starting character position
                of the substring. The first character in a string is at position 1. If position
                is negative, then the position is relative to the end of the string. A position
                of -1 denotes the last character.</p>
              <p><samp class="parmname">len</samp> is the length,
                or number of characters, to return. If len is 0, the output is an empty string.
                If len is negative, then the function returns null. This parameter is
                optional.</p>
              <p>Example: Return the 13th, 14th, and 15th character from each
                account
                ID.</p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>substr(Account_Id,13,3)</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>title</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 "> Returns the string with the initial character of every word in uppercase and
              the remaining characters in lowercase. For example, “united states” becomes
              “United States.”</td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p>
                <code>title(<samp class="parmname">field</samp>)</code>
              </p>
              <p><samp class="parmname">field</samp> is
                the text (dimension) field or string on which to apply title
                casing.</p>
              <p>Example: Apply title casing on the opportunity names to ensure
                consistent casing on these
                values.</p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>title(Opp_Name)</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>trim</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Removes the specified substring from the beginning and end of a string. If no
              string is specified, remove the space characters from the beginning and end of a
              string. </td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p>
                <code>trim(<samp class="parmname">field</samp>,<samp class="parmname">valueToBeRemoved</samp>)</code>
              </p>
              <p><samp class="parmname">field</samp>
                is the text (dimension) field or string to remove the specified substring
                from.</p>
              <p><samp class="parmname">valueToBeRemoved</samp> is the value removed from the
                string. This parameter is optional. If you don't specify a valueToBeRemoved, the
                transformation removes the leading and trailing spaces.</p>
              <p>Example: Remove
                the two leading spaces before and after a
                string.</p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>trim('  Spaces Before and After  ')</code></pre>
            </td>

          </tr>
          <tr class="">
            <td data-label="String Function" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e55 ">
              <code>upper</code>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e58 ">Returns the string with all characters in uppercase. If string is null, then
              the result is null.</td>

            <td data-label="Syntax" class="slds-cell-wrap" style="vertical-align:top;" headers="d191127e61 ">
              <p>
                <code>upper(<samp class="parmname">field</samp>)</code>
              </p>
              <p><samp class="parmname">field</samp> is
                the text (dimension) field or string to convert to uppercase.</p>
              <p>Example: You
                have a column First_Name that accepts freeform entry for users to enter their
                first name. As a result, some names are in uppercase, some in lowercase, and
                others in mixed case. Convert them to all to uppercase characters to make the
                casing
                consistent.</p>
              <pre class="line-numbers slds-box slds-box_x-small slds-theme_shade slds-m-top_medium slds-m-bottom_medium slds-scrollable_x"><code>upper(First_Name)</code></pre>
            </td>

          </tr>
        </tbody>
      </table>

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/images/icon_note.png)

Note Functions that don't handle null values explicitly don’t convert NULL values to be empty (for strings) or 0 (for numerics). For example, a `concat` output returns NULL if any of the concatenated fields have a null value on that row. So if the formula looks like `concat(first_name, last_name)`, the returned data with a NULL value for last\_name is:

```
First Name | Last Name | Output
          Alice      | Smith     | Alice Smith
          Bob        | NULL      | NULL
```

To handle null values, you can use the `concat` function with another function. For example: `concat(first_name, coalesce(last_name, ''))`

- **[Notation for String Formulas](https://help.salesforce.com/s/articleView?id=analytics.bi_integrate_recipe_string_functions_notation.htm&release=264.0.0&type=5)**  
    In CRM Analytics, use formulas to create custom calculations. If you manually type your formulas, use single quotes `'` for string literals and double quotes `"` for joined fields with dot notation or reserved keywords. If you use the recipe builder tool instead of typing, the correct single or double quote is automatically used.
- **[Reserved Keywords in Formulas](https://help.salesforce.com/s/articleView?id=analytics.bi_integrate_recipe_string_functions_keywords.htm&release=264.0.0&type=5)**  
    In CRM Analytics, Data Prep has reserved keywords that need special handling when manually writing formulas. Use double quotes `"` when referencing dataset columns that share a name with reserved keywords. To avoid cross-referencing your column names to this list, the best practice is to use double quotes around all column names.