RuffRuff App RuffRuff App by Tsun

[Looker Studio] How to Use the STARTS_WITH Function and Practical Examples | Calculated Fields

[Looker Studio] How to Use the STARTS_WITH Function and Practical Examples | Calculated Fields

In this article, we will provide a clear explanation of how to use the STARTS_WITH function in Looker Studio, along with specific examples of its application. By utilizing the functions available in Looker Studio, you can process and visualize your data effectively.

In many cases, you can process data from GA4 (Google Analytics 4) and Search Console using Looker Studio's calculated fields without needing to use BigQuery. The STARTS_WITH function is used to determine if a string starts with a specified substring. We will explain practical examples based on GA4 data using connectors, so be sure to make the most of this function.

What are Calculated Fields in Looker Studio?

Calculated Fields in Looker Studio are a handy feature that allows you to create custom fields by using operators (such as addition, subtraction, multiplication, division), functions, and regular expressions based on existing items for use in reports.

Also, for basic usage of Looker Studio, please refer to the "How to Use Looker Studio" guide. Looker Studio is a very convenient tool that is free to use and allows for the creation of easy-to-understand reports by connecting to various data sources, so let's make active use of it.

What is the STARTS_WITH Function?

The STARTS_WITH function is used to determine if a field begins with a specified string. If the field starts with the specified string, the function returns true; otherwise, it returns false. It's important to note that the function is case-sensitive, so the string must be specified correctly.

While the STARTS_WITH function does not use regular expressions, there are similar functions, such as REGEXP_MATCH and REGEXP_CONTAINS, that do. Using regular expressions allows you to specify not only a fixed number of characters but also patterns within the string. Since regular expressions require a certain level of knowledge, it's important to evaluate whether your goal necessitates the use of regular expressions. If not, consider using functions that do not require regular expressions.

For a list of functions that use regular expressions, their alternatives, and detailed instructions on how to use regular expressions, please refer to the official help documentation below.

※Official Help for Looker Studio: Regular Expressions in Looker Studio

Syntax

The syntax for the STARTS_WITH function is as follows:

STARTS_WITH("Target Field", "Search String")

Specify the data field to be checked for starting with a particular string in "Target Field".
Specify the string to be used as the criterion for the check in "Search String".

How to Use the STARTS_WITH Function

To use the STARTS_WITH function, you need to create a calculated field in Looker Studio. There are two types of calculated fields: data source calculated fields and chart-specific calculated fields. This article will focus on creating a data source calculated field, but for more detailed differences between the two, please see the differences between data source calculated fields and chart-specific calculated fields.

Use case : Determine page titles starting with specific characters in GA4 using Looker Studio

Let's assume a case where you need to determine whether a page title on a particular site starts with a certain character. Consider the following page titles:

[Looker Studio] How to Use the REGEXP_EXTRACT Function... [Looker Studio] How to Use the REGEXP_CONTAINS Function... [Looker Studio] How to Use the CAST Function... [Looker Studio] How to Use the IMAGE Function...

We will determine only the page titles that start with "[Looker Studio]". First, set up a calculated field as follows.

lookerstudio-starts_with-setting

(Quote:Looker Studio)

① Field Name: Please enter any field name.

② Formula: 

STARTS_WITH(Page title,"[Looker Studio]")

In this formula, it specifies whether the page title starts with [Looker Studio].

③ Save: Once you have completed entering the information, click save.

 A field called the Page Title Classification has been created as follows.

lookerstudio-starts_with-metric

 (Quote:Looker Studio)

 We will actually use the created fields in the reports."

 

lookerstudio-starts_with-graph

 (Quote:Looker Studio)

 You can see that only pages with titles starting with "[Looker Studio]" have a true evaluation. However, this alone does not provide any insights. By filtering to only show true results or counting the number of true results, you can display or count only the page titles that start with a specific string. For more on filtering methods, please refer to [Looker Studio] How to Use Filters | Common Settings Examples Including Date Selection and Filtering Specific Pages.

Relevant Looker Studio Official Documentation

Looker Studio Official Help : About calculated fields

Looker Studio Official Help : Function list

Back to blog

Featured collection