Creating Formulas with Character Functions

Objective

After completing this lesson, you will be able to use character string functions to extract, replace, and format text in a Web Intelligence document.

Character String Functions

You will learn how to use character functions in Web Intelligence. The lesson provides several examples to show how you can apply these functions.

Example: Extract Characters Using the Right Function

In the eFashion universe, the year object returns the year as a four-digit value, such as 2025. If you want to display the year in a two-digit format, such as 25, use the Right function to show only the last two characters.

The Right function displays a fixed number of characters, starting from the right of the character string, and removes the others.

Two tables labeled 2024 and 2025 are renamed to Year 24 and Year 25 with identical quarterly sales revenue data.

Function: Right

The Right function returns the rightmost characters of a string.

string Right(string;num_chars)

To show only the last two characters of the year, use the following syntax:

=Right([Year];2)

The example syntax can be broken down into the following parts:

  • [Year] Name of the object that contains the data.
  • 2 Number of characters to display from the right of the character string.

Section Header Modification

To include the year name and display the last two digits in the section header, use the following syntax:

=NameOf([Year])+" "+Right([Year];2)

The example syntax can be broken down into the following parts:

  • NameOf([Year]) To display the name of the Year object.
  • +" " To concatenate a space after the object name.
  • + Right([Year]);2) To concatenate and display two characters starting from the right end of the character string.
Year 24 heading is generated using the formula =NameOf([Year]) + + Right([Year], 2), with quarterly sales revenue listed below.

Example: Extract Characters Using the Substr Function

The Store name object in the eFashion universe returns the name of each store in the Fashion company. Each store name includes the prefix "e-Fashion".

If you want to remove the "e-Fashion" prefix from each store name, you need to adjust the string. Removing the "e-Fashion" prefix can be difficult because store names have different lengths. The Right and Left functions do not work in this case.

You can remove the "e-Fashion" prefix by using the SubStr function.

Store names in a table are simplified by removing the e-Fashion prefix from each entry.

Function: SubStr

The SubStr function extracts a specified character string from within a string.

string Substr(string;start;length)

To display the store name without the "e-Fashion" prefix, use the following syntax:

=SubStr([Store name];11;Length([Store name]))

The example syntax can be broken down into the following parts:

  • [Store name] The string from which the substring is to be extracted.
  • 11 The position of the first character in the input string to be extracted.
  • Length({Store name]) The number of characters to be extracted.

Using the SubStr Function to Modify the Display

The report displays the store names without the e-Fashion prefix.

A formula extracts text from the eleventh character onward in the Store name column of a table listing various store locations.

Example: Replace Text Using the Replace Function

In this example, you want to show the word "Quarter" instead of the letter "Q."

Abbreviated quarter labels in sales revenue tables for Years 24 and 25 are expanded from Q1–Q4 to Quarter 1–Quarter 4.

Function: Replace

The Replace function replaces part of a string with new text.

string Replace(replace_in;replaced_string;replace_with)

Use the following syntax:

=Replace([Quarter];"Q";"Quarter ")

The example syntax can be broken down into the following parts:

  • [Quarter] Describes the name of the object that retrieves the data.
  • "Q" Describes the value stored in the database followed by 1 through 4 to indicate the first through fourth quarters of the year.
  • "Quarter " Describes the character string that replaces "Q" in every instance.

Using the Replace Function to Modify the Display

The Quarterly Revenue figure shows the report that appears when you replace the Quarter column with the new variable.

A formula replaces Q with Quarter in the quarter column for sales revenue tables for Year 24 and Year 25.

Example: Find a Character's Position Using the Pos Function

You are working on a report that includes the Store and Address columns.

In the Address column, you want to show only the street names for each eFashion store. The Address object returns both the building number and the street name. The number of spaces before the street name starts is not consistent. To solve this, you need to create a substring that returns only the street name.

Each address has a space after the building number. Create a formula that finds the position of this space for each entry. Use this position as the starting point for the SubStr function.

Address column values are simplified by removing street numbers, leaving only street names for each store location.

Create a Variable Named Space

The Space variable finds the first space in each address string. If you add a Space column to the report, it shows the number of characters before the street name for each address.

Function: Pos

The Pos function returns the starting position of a text pattern in a string.

int Pos(test_string;pattern[;start][;end]])

Use the following syntax:

=Pos([Address] ; " ")

The example syntax can be broken down into the following parts:

  • [Address] The string to be tested for the text pattern.
  • " " The text pattern.

Create a Variable Named Address

The number that the Space variable returns is the count of characters before the street name starts. You can now create a variable called Address that removes the building number from the address.

Function: SubStr

The SubStr function extracts a specified character string from within a string.

string Substr(string;start;length)

Use the following syntax:

=SubStr([Address];[Space]+1;Length([Address]))

The example syntax can be broken down into the following parts:

  • [Address] The string from which the substring is to be extracted.
  • [Space] The position of the first character in the input string to be extracted.
  • Length([Address]) The number of characters to be extracted.

Using the Pos Function

To finish the report, delete the Space column. Replace the Address column with the Address variable you created.

A table splits address fields into street numbers and street names using formulas to find the space position and extract the street name substring.

For more information about this topic, please read SAP BusinessObjects Web Intelligence User's Guide

Let's Summarize What You've Learned

  • Use character string functions like Right, Left, and SubStr to extract specific parts of text in reports.
  • Apply the Replace function to substitute parts of a string with new text for clearer report formatting.
  • Use the Pos function to find character positions and create dynamic substrings based on variable text lengths.
  • Understand when to use variables versus formulas for flexible and reusable calculations in your documents.

Apply String Manipulation Formulas

Business Example

Your manager asks you to create a new document listing all employees and their job roles for each store location. This report is for a new internal staff directory and must be easy to read at a glance. To ensure the employee list is concise and professional, format the names to show the first initial of the first name, followed by a period and the full last name.