[Looker Studio] How to Use the CONCAT Function and Practical Examples | Calculated Fields
In this article, we will clearly explain how to use the CONCAT function in Looker Studio and provide concrete examples of its application. By utilizing the functions available in Looker Studio, you can process and visualize data.
The CONCAT function is used to concatenate two or more strings into a single field. We will introduce multiple specific examples of its use in GA4 (Google Analytics 4).
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 CONCAT Function?
The CONCAT function is used to concatenate two or more strings. By using this function, it is possible to display the values of different data fields as a single string. It can also be used to add a specific string to a particular data field. For example, if there are two data fields, such as last name and first name, the CONCAT function can be used to create a new data field that combines them into a single full name field.
Syntax
The syntax for the CONCAT function is as follows
CONCAT("String1","String2","String3"...)
Set the data fields or text you want to concatenate as "strings".
You can concatenate two or more strings.
The strings are concatenated in the order they are entered. In the example syntax, String1, String2, and String3 are concatenated.
How to Use the CONCAT Function
To use the CONCAT 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.
I will explain how to use the CONCAT function in detail, using GA4 (Google Analytics 4) data as an example.
Use case: Combining and Displaying Source, Medium, and Campaign from GA4 in Looker Studio
Create a new dimension by combining the two dimensions, Session Source / Medium and Session Campaign, into a single dimension called Session Source / Medium / Campaign.
Set the calculated field as follows.
(Quote:Looker Studio)
① Field Name: Please enter any field name.
② Formula:CONCAT(Session source / medium," / ",Session campaign )
To prevent the string from being concatenated without a "/", we have set it up so that a "/" is always inserted between media and campaigns.
③ Save: Once you have completed entering the information, click save.
A field called the Session source / medium / campaign has been created as follows.
(Quote:Looker Studio)
We will use the created field in the report. By configuring the Looker Studio report as follows, the Session source / medium / campaign will be displayed in a single field.
(Quote:Looker Studio)
Use case: Displaying Gender and Age Combined in GA4 with Looker Studio
Create a new dimension that combines both gender and age of users into one dimension labeled Gender:Age.
Set up the calculated field as follows:
(Quote:Looker Studio)
① Field Name: Please enter any field name.
② Formula:CONCAT(Gender, "/",Age )
To prevent the string from being concatenated without a "/", we have set it up so that a "/" is always inserted between gender and age.
③ Save: Once you have completed entering the information, click save.
A field called the Gender/Age has been created as follows.
(Quote:Looker Studio)
The fields created will be used in the report. By setting up the Looker Studio report as shown below, gender and age group can be displayed in a single field. When you want to see graph transitions with a combined view of gender and age group, you can use the CONCAT function.
(Quote:Looker Studio)
Use case: Displaying Page URLs by Combining Hostname and Page Path in Looker Studio
Create a new dimension that combines the hostname and page path into a single parameter-free page URL.
Set up the calculated field as follows:
(Quote:Looker Studio)
① Field Name: Please enter any field name.
② Formula:CONCAT("https://",Hostname,Page path and screen class)
To ensure that the string forms a complete URL, the initial "https://" is set as a fixed string.
③ Save: Once you have completed entering the information, click save.
A field called the Page URL (excluding parameters) has been created as follows.
(Quote:Looker Studio)
The created field will be used in the report. By setting up the Looker Studio report as follows, the page URL (without parameters) is now displayed.
(Quote:Looker Studio)
The CONCAT function allows you to flexibly concatenate strings into a single string. Please make use of it.
Relevant Looker Studio Official Documentation
Looker Studio Official Help : About calculated fields
Looker Studio Official Help : Function list