RuffRuff App RuffRuff App by Tsun

[Looker Studio] How to Use Calculated Fields | With a Handy List of Functions for Copy and Paste

[Looker Studio] How to Use Calculated Fields | With a Handy List of Functions for Copy and Paste

[Looker Studio] How to Use Calculated Fields | With a Handy List of Functions for Copy and Paste

This article clearly explains how to use the useful calculated fields in Looker Studio. Calculated fields allow you to create custom metrics using existing data points, operators (such as addition, subtraction, multiplication, division), functions, and regular expressions to enhance your reports. Be sure to make use of this convenient feature.

What is Looker Studio (formerly Data Portal)?

Looker Studio is a free reporting tool provided by Google that connects to various data sources and allows for the creation of clear, fully automated reports. For detailed instructions on how to use it, please see "【Complete Preservation Edition】How to Use Looker Studio (formerly Data Portal) | Easily Explained Features and Benefits".

While Looker Studio is a free and highly functional tool, it takes some time to master. However, using templates allows for quick, high-quality report creation. Instead of building a report from scratch, you can customize only the necessary parts of a pre-made template, significantly reducing the time needed.

There are various templates available online, ranging from free to paid. If you are looking for high-quality templates, please use the Looker Studio templates from 88studio's one-time purchase plan, utilized by over 2,000 companies. With a single purchase, you can create unlimited reports for multiple sites. The reports can be completed in just a few minutes by copying, and customization is entirely flexible. Additionally, we have the leading web analyst as an advisor. Whenever there are changes in specifications from media sources like GA4, we promptly update our templates, so you can always use them with confidence.

Popular Templates: GA4 Monthly Report Template popular for reports to clients and internal use

GA4 Monthly Report Template[4007]

Demo Report

Report detail

Popular Templates: GA4 Standard Report Template that simplifies daily number checks

GA4 Standard Report Template[4004]

Demo Report

Report detail

What are Calculated Fields in Looker Studio?

Calculated fields are a useful feature that allows for the creation of custom fields for reports by using operators (such as addition, subtraction, multiplication, and division), functions, and regular expressions based on existing items.

Looker Studio fields are categorized into two types: dimensions (analytical axes such as date and gender) and metrics (numerical values such as user counts and page views). With calculated fields, it is possible to create new custom fields, both dimensions and metrics.

The Difference Between Calculated Fields in Data Sources and Chart-Specific Calculated Fields

There are two types of settings for calculated fields: "Calculated Fields in Data Sources" and "Chart-Specific Calculated Fields."

The following table summarizes the differences between these types of calculated fields. As a rule of thumb, it is generally easier to use "Calculated Fields in Data Sources." Use "Chart-Specific Calculated Fields" only when it is necessary to configure calculated fields using integrated data sources.

Feature Calculated Fields in Data Sources Chart-Specific Calculated Fields
Who can create Editors of the data source Editors of the report
Scope of use for the created calculated fields All reports using that data source Only the chart for which they were created
Creating calculated fields using other calculated fields Possible Not possible
Handling integrated data Not possible Possible

 

What You Can Do with Looker Studio's Calculated Fields

The capabilities of using calculated fields can be broadly categorized into the following three:

  1. Creating new metrics using numbers and standard operators (addition, subtraction, multiplication, division)
  2. Processing data using functions
  3. Creating branching logic using CASE statements

Understanding these may seem abstract, so in the following sections, we will introduce specific ways to use calculated fields and practical examples using handy functions. Please consider them as references.

How to Use Looker Studio's calculated field

Calculated fields can be easily created in three steps. Here, we will try to create a "new user rate," which is not a default metric, using the GA4 data source.

Select "Add calculated field" from the data source

Open the Looker Studio data source, click "Add Field" at the top right, and then you will see two options. Choose "Add calculated field."

  Enter "Field Name" and "Formula," then save

Set it as follows and save. Note that these settings can be changed later.

  • Field Name: Enter a name that is easy to understand later
  • Formula: For the new user rate, enter "number of new users / number of active users"

(Optional) Change the type

After saving, close the settings screen, and the list of fields will be displayed. If you enter the "new user rate" that you just set in the search box at the top right, the item you created will be displayed as follows.

The default type is numerical (e.g., 0.5), but since you want to display the new user rate as a percentage (50%), change the type to "%" using the dropdown menu.

This completes the setup for the calculated field. Once the setup is complete, the item can be used in reports immediately as shown below.

 

List of Useful Functions for Calculated Fields in Looker Studio

Here, we introduce a list of useful functions for creating calculated fields.

The "HYPERLINK" function that can generate a link URL from text data

The HYPERLINK function converts text into a clickable hyperlink. The basic syntax is as follows:

HYPERLINK("URL", "Link Text")

  • "URL" specifies the address of the hyperlink destination. This is the webpage URL that opens when clicked.
  • "Link Text" is the text displayed on the link. This is visible to the user, and clicking on it will take them to the specified URL.

Example of use: Creating a list of page titles with links in GA4 in Looker Studio

Set up the calculated field as follows:

HYPERLINK(Full page URL, Page title)

Using this in an actual report creates a list of clickable page titles, and clicking on one opens the actual URL in a new window.

The 'REGEXP_REPLACE' function that can transform or delete text matching certain conditions into another string

The REGEXP_REPLACE function replaces text within a string that matches a regular expression pattern with another string. The basic syntax is as follows.

REGEXP_REPLACE(target_string, 'pattern_to_search', 'replacement_string')

  • target_string: The original text you want to modify.
  • 'pattern_to_search': Parts matching this pattern within the target string are searched for.
  • 'replacement_string': The text that matches is replaced with this string. 

Example use: Excluding parameters from the full URL of a page in Looker Studio

Set up a calculated field as follows. This function removes all characters following the '?' symbol from the full URL of the page.

REGEXP_REPLACE(full page URL, '\?.+', '')

 

This makes the 'full page URL' dimension, with parameters excluded, available for use.

  The "CASE" function that can transform data based on specific conditions

The CASE function can be utilized in various cases, such as data classification, labeling, and transforming data based on specific conditions. For instance, when categorizing products by price range, you would set it up as follows:

CASE
WHEN price < 100 THEN "Inexpensive"
WHEN price BETWEEN 100 AND 500 THEN "Standard"
WHEN price > 500 THEN "Expensive"
ELSE "Price Undefined"
END

In this example, if the price is less than 100, it is labeled "Inexpensive", the range between 100 and 500 is "Standard", and above 500 is "Expensive". If none of the conditions are met, it displays as "Price Undefined".

  Use case: Converting GA4 Device Categories in Looker Studio

The device categories in GA4 are, by default, classified as follows:

  • desktop
  • mobile
  • tablet

By setting up calculated fields, we can convert each category as follows:

CASE
WHEN Device category = "desktop" THEN "Not mobile"
WHEN Device category = "mobile" THEN "mobile"
WHEN Device category = "tablet" THEN "Not mobile"
ELSE "other"
END 

With this, you now have access to your own custom device categories.

  Related Looker Studio Official Documentation

Looker Studio Official Help: About calculated fields

Looker Studio Official Help: Function List

We also recommend this article. 

[Looker Studio]How to download the report as PDF

The function to download reports as PDFs in Looker Studio (formerly Data Studio) is very useful for sharing reports internally and externally as reporting materials, or printing them on paper for use as presentation materials. This article provides an easy-to-understand explanation of how to use and what to expect from the PDF download function.

How to represent GA4 content groups in Looker Studio

GA4 content group is a grouping of specific content within a site. For example, you can group content by blog category, site menu, etc. This allows you to analyze visitor preferences and parts of your site. Normally, content groups are set up using Google tag manager, but Looker Studio offers a similar setup, so if you cannot use Google tag manager but want to group pages, try this.

[Looker Studio] How to export data from a graph to a Google Spreadsheet or CSV (Excel)

Looker Studio (formerly Data Studio) allows you to export the graphs you create in a variety of formats. This article provides a clear explanation of the benefits, usage, and caveats of the export function.

Back to blog

Featured collection