Looker Studio Function : TRIM
TRIM Function in Looker Studio – Clean Text Data Instantly
Category: Text Function
The TRIM function in Looker Studio is a text function used to remove leading and trailing spaces from a text value. While it may look simple, TRIM plays a very important role in data cleaning and consistency, especially when working with user-entered or imported text data.
In real reporting scenarios, data often comes with extra spaces due to manual entry, system exports, or integrations between different platforms. These unwanted spaces can cause issues in filtering, grouping, comparisons, and joins. TRIM helps resolve such problems by cleaning the text directly inside Looker Studio.
From a BI perspective, TRIM is frequently used before applying comparisons, filters, or text matching functions like STARTS_WITH or CONTAINS_TEXT. It ensures accurate results without modifying the original data source. Since TRIM operates at row level and has minimal processing overhead, it performs efficiently even on large datasets.
Overall, TRIM is a must-use function for improving data quality and ensuring reliable reporting in Looker Studio dashboards.
Purpose of SUBSTR
1. Remove Extra Spaces
Removes leading and trailing spaces that cause mismatches in text comparison.
2. Improve Data Consistency
Ensures uniform text values across datasets for accurate reporting.
3. Clean User-Entered Data
Fixes formatting issues caused by manual or system-generated text input.
4. Reliable Text Matching
Improves accuracy when using filters or conditional text functions.
Type of Calculation & Practical Use Cases
1. Text Cleaning
Cleans unwanted spaces from text fields before analysis or grouping.
2. Calculated Dimensions
Used in calculated dimensions to standardize text values.
3. Data Preparation
Acts as a lightweight data preparation step inside Looker Studio.
4. Filter Accuracy
Prevents incorrect filtering results caused by hidden whitespace.
TRIM(text)
TRIM Function Function – Parameters Table
| Parameter | Type | Description |
|---|---|---|
| text | Text | The text value from which spaces will be removed |
How Does the TRIM Function Work?
TRIM removes all spaces from the beginning and end of a text value. It does not remove spaces between words.
For example, " Sales Report " becomes "Sales Report". The function processes each row independently and returns cleaned text. If the text value is NULL, TRIM returns NULL.
When Should You Use TRIM Function?
When text values contain extra spaces
Before applying text comparisons or filters
When cleaning user-entered data
When preparing data for grouping
When improving data quality inside reports
Examples of TRIM Function
Example 1: Clean Customer Name
TRIM(Customer_Name)
Example 2: Fix Product Category
TRIM(Product_Category)
Example 3: Use with LOWER Function
LOWER(TRIM(Email_ID))
Tips & Best Practices
Use TRIM before text comparisons
Combine TRIM with LOWER for clean matching
Apply TRIM consistently across similar fields
Test output using table views
Avoid unnecessary nested text functions
No, TRIM removes only leading and trailing spaces, not spaces between words within the text value.
TRIM does not change character case; it only removes extra spaces from the beginning and end of text.
No, numeric values must be converted to text before applying the TRIM function.
If the input text is NULL, the TRIM function returns NULL without performing any operation.
No, TRIM is lightweight and performs efficiently even when applied to large datasets.