Information noteThe "Set verbatim=1" statement is included in the example to ensure that the spaces are not automatically trimmed before the demonstration of the LTrim function. See Verbatim for more information.
Results
Load the data and open a sheet. Create a new table and add this field as a dimension:
InputText
Create the following calculated dimension:
=LTrim(InputText) to remove leading spaces from InputText.
Results table
InputText
LTrim(InputText)
' abc '
'abc '
' def '
'def '
The output of the LTrim function removed all leading spaces to the left of the original text but retained all trailing spaces.
Example - LTrim scenario
Overview
A customer relationship management (CRM) system contains records with inconsistent data entry that include extra leading spaces. For reporting purposes, the data requires cleaning to remove these spaces and to ensure proper sorting and grouping of customer names.
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset which is loaded into a data table called Example.
One field in the data table called CustomerName.
Load script
Set verbatim=1;
Example:
Load * inline [
CustomerName
' John Doe'
'Jane Smith'
' Michael Johnson'
'Emily Davis'
];
Information noteThe "Set verbatim=1" statement is included in the example to ensure that the spaces are not automatically trimmed before the demonstration of the LTrim function. See Verbatim for more information.
Results
Load the data and open a sheet. Create a new table and add this field as a dimension:
CustomerName
Create the following calculated dimension:
=LTrim(CustomerName) to remove any leading spaces from CustomerName.
Results table
CustomerName
LTrim(CustomerName)
' Michael Johnson'
'Michael Johnson'
' John Doe'
'John Doe'
'Emily Davis'
'Emily Davis'
'Jane Smith'
'Jane Smith'
The output shows that the LTrim function removed all leading spaces from the original string values in CustomerName.
Example - LTrim advanced scenario
Overview
This example removes all leading spaces from the original text string. The chart expression includes measures that use the Len function to count the characters in the string before and after using the LTrim function.
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset which is loaded into a data table called Example.
Information noteThe "Set verbatim=1" statement is included in the example to ensure that the spaces are not automatically trimmed before the demonstration of the LTrim function. See Verbatim for more information.
Results
Load the data and open a sheet. Create a new table and add this field as a dimension:
String
Create the following calculated dimension:
=LTrim(String), to remove any extra leading spaces.
Create the following measures:
=Len(String), to count the length of the original string.
=Len(LTrim(String)), to count the length of the string after the leading spaces have been removed.
Results table
String
LTrim(String)
Len(String)
Len(LTrim(String))
' abc '
'abc '
10
7
' def '
'def '
6
5
When you compare the output of the LTrim function to the original string values in the script, you can see how all leading spaces have been removed.
The following code shows how to use the function in a load script.
Set verbatim=1;
Example:
Load *,
len(LtrimString) as LtrimStringLength;
Load *,
ltrim(String) as LtrimString;
Load *,
len(String) as StringLength;
Load * Inline [
String
' abc '
' def '];
Information noteThe "Set verbatim=1" statement is included in the example to ensure that the spaces are not automatically trimmed before the demonstration of the ltrim function. See Verbatim for more information.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. The information does not usually directly identify you, but it makes the site work as you expect it to and can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies by clicking on the different category headings to find out more and change your settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
Privacy & Cookie Notice
Manage Consent Preferences
Strictly Necessary Cookies
Always Active
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work.
Functional Cookies
These cookies enable the website to provide enhanced functionality and personalization. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies, then some or all of these services may not function properly. These cookies do not typically store personal information enabling us to identify you, but are based on uniquely identifying your browser and internet device.
Performance Cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site and make it easier to navigate. For example, they help us to know which pages are the most and least popular and see how visitors move around the site. When analyzing this data it is typically done on an aggregated (anonymous) basis.
Advertising Cookies
These cookies may be set through our site by our advertising partners to build a profile of your interests and show you relevant advertisements on other sites. They do not typically store personal information enabling us to identify you, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less relevant advertising.