Looker Studio (GDS) visualization tasks involve acquiring and visualizing data directly from data sources or through connectors (agents). At this stage, the data we obtain is listed in the form of metrics and dimensions. These fields, listed in relation to the data source, can be controlled through various functions based on user requirements.
In simple terms, Looker Studio functions can be described as calculated fields (calculated fields), which allow us to manipulate dates, numerical operations, values (value), and formats, and can be recorded either at the data chart level (chart level) or at the data source level. For more details on this topic, please refer to the article titled Looker Studio Calculated Fields (Calculated Fields). In this article, I will discuss the functions we can use within calculated fields. First, let’s briefly recall the differences between calculated fields at the data chart level and at the report/data source level.
| Operation | At Data Source Level | At Data Chart Level |
|---|---|---|
| Is a data source editor required? | + | |
| Will blended data (blended) be used? | + | |
| Will other calculated fields be used? | + | |
| Will it be used in other reports and charts? | + |
It is beneficial to take into account these differences when creating calculated fields. Otherwise, you might end up creating separate calculated fields that perform the same operation but are calculated individually for each data visualization, and you may be forced to manually adjust each calculated field whenever any updates or edits are required. On the other hand, for calculated fields that will be used only in a few visualizations, it may not be necessary to perform operations at the data source level; in such cases, operations at the data visualization level (depending on the conditions in the table) will suffice.
To create a calculated field at the data visualization (chart) level, you can click the Create new field link in the Metrics and/or Dimensions section, either during or after the visualization stage. Then, the relevant operations can be performed within the opened field.
Blended data (blended data) also works similarly at the data visualization level. A field (field) is created again for the metric and/or dimension, and the newly created calculated field is added to the relevant section1. Of course, a calculated field intended to be used as a key must return the same data for both data tables, including data types, etc. Otherwise, an error will occur.
Unlike operations at the data visualization level, at the data source level, as shown in the table above, different calculated fields can also be used within formulas and across different charts and reports.
Thus, managing the corresponding calculated fields becomes significantly easier, and a much broader range of operations can be visualized through data charts.
We can also define parameters at the data source level. However, for now, I am keeping the topic of parameters for a separate article, outside the scope of this post.
Functions
Data Studio functions are predefined formulas that enable a wide range of operations—including controls, value manipulation, merging, data type conversions, etc.—beyond basic mathematical operations, and can be used within calculated fields (for metrics and dimensions).
Similar to functions available in electronic spreadsheet applications such as Microsoft Excel and Google Sheets, or in query languages such as SQL, Data Studio functions are designed for specific purposes and must follow specific syntax rules to be used.
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END;
Currently, over 50 functions are available for use in calculated fields, with this number expected to grow over time2. These functions are grouped under various headings—data aggregation (aggregation), arithmetic (arithmetic), conditional (conditional), date (date), geographic/geo (geo), text (text), and miscellaneous (miscellaneous) operations—based on their intended purposes3 4.
Function Usage
Before moving on to the most commonly used formulas and example operations, it’s worth remembering a few key points regarding formula usage.
- We can use formulas (at the data visualization and/or data source level) by either creating a new field (field) or by modifying an existing (non-default) custom metric or dimension. We cannot perform operations on a standard field (field).
- If a formula runs successfully, a green checkmark appears under the formula editor. Once this step is completed, the formula can be saved and applied to the data pulled from the data source.
- When a formula is entered into the formula editor, a help window appears, providing examples of usage and relevant information.
- Calculated fields created at the data source level are marked with fx.
Finally, text operations within metric fields are processed as binary (boolean) values, and depending on the selected operation, if Count is selected, the total number of processed data items is returned, while if Count Distinct is selected, the total number of unique values is returned.
Data Types
Data Studio supports various data types (numerical, text, boolean, URL, etc.) to describe operations and results within calculated fields. These data types apply to all data obtained through predefined data sources and connectors. 5
| Data type | Expected data | Example |
|---|---|---|
| Numeric (numeric) | Numeric value | 1,234.56 |
| Percent (percentage) | Numeric ratio | 61.73% |
| Duration (duration) | A whole number representing a duration in seconds. This will be formatted as a standard time display in reports. | 01:43:19 |
| Currency (currency) | Monetary value. This will be formatted with the appropriate currency symbol in reports. Currency codes are also selected. | $1,234.56, 173.9 €, ¥30,093, etc. |
| Text (text) | Zero or more letters, digits, characters, or symbols | A1B2C3 |
| Date & Time | Calendar date, date and time, or an abstract date or time index. This will be formatted according to local settings. | 2020-09-21, 2020-09-21 12:35 PM, Q4 2020, Week 1, 13, etc. |
|
| Boolean (binary) | A logical value | true, false |
| Geo (location) | A value representing a geographic region, such as country name, latitude and longitude, ISO code, or Google Ads audience ID | Istanbul, United Kingdom, 51.5074,-0.1278, 1006886 |
| URL | An internet connection | https://google.com |
| Hyperlink (internet link) | A clickable, headline-enabled internet link created using the HYPERLINK function | |
| Image (image) | An image created using the IMAGE function | |
| Image Link (image link) | An clickable image created using the HYPERLINK function | |
Field definitions for data types can be adjusted through selection among appropriate options. Additionally, data type adjustments can be made within calculated fields using the CAST function6. However, conversions between types are subject to specific constraints.
| Source data type | Target data type |
|---|---|
| Text | DATE, DATETIME, NUMBER |
| Number | TEXT |
| Date | DATETIME, TEXT |
| Date & Time | DATETIME, TEXT |
After covering the essential topics, we can briefly discuss a few prominent functions.
Example Functions
Below, I’ve attempted to provide descriptions and examples for some commonly used functions. New examples and functions may be added over time7 8. You can also share your frequently used calculated field formulas and functions in the comments.
CASE
Enables conditional operations. It is treated similarly to SQL9. Different formulas can be used for condition checks within a formula. In the example below, the utm_medium parameter within the Page content is being checked and the value is assigned to a channel group accordingly. As shown, values are being checked using REGEXP_MATCH within the CASE statement.
CASE
WHEN REGEXP_MATCH(Page,'.*utm_medium=e-mail.*') THEN "Email"
WHEN REGEXP_MATCH(Page,'.*utm_medium=paid-search.*') THEN "Paid Search"
ELSE Default Channel Grouping
END
CONCAT
Combines multiple text strings into a single text string10. The example below combines the domain name with the page URL to create a complete URL, and the resulting link is associated with the page title using the HYPERLINK function.
HYPERLINK(CONCAT(Hostname, Page), Page Title)
HYPERLINK
As seen in the previous example, the HYPERLINK function allows defining a label (label) for a link and makes that label clickable11.
REGEXP_EXTRACT
Allows splitting a value into components12. For example, you can use the REGEXP_EXTRACT function to extract query parameters from within the Page and access the parameter values as well.
REGEXP_EXTRACT(Page, 'q=([^&]+)')
When we want to check whether the values satisfy the specified conditions, we use the REGEXP_MATCH function13. Of course, this is not the only option available; other functions such as REGEXP_CONTAINS, STARTS_WITH, and ENDS_WITH also offer different capabilities. In the following example, it will return True if either apple or iphone is present in the Query content.
REGEXP_MATCH(Query, '(apple|iphone)')
REGEXP_REPLACE
Allows replacing values with a specified value when the given values match a specified pattern. For instance, you can reevaluate issues such as typos in search queries or campaigns using the REGEXP_REPLACE function14.
REGEXP_REPLACE(Page, 'stanley', 'thermos')
UPPER / LOWER
Converts all characters in the given value to15 or lowercase16.
UPPER(Campaign)
LOWER(Campaign)
In addition to the examples above, sample reports accessible through search engines can also be very helpful in understanding the usage patterns. At this stage, it is important to verify the relevant formulas and ensure that the values associated with the data sources are accurate and consistent. In such cases, I recommend using a table (table) visualization to validate the operations.
Footnotes
- Calculated fields. Data Studio Help ↩
- Use functions in calculated fields. Data Studio Help ↩
- Function list. Data Studio Help ↩
- Function references ↩
- Data types. Data Studio Help ↩
- CAST. Data Studio Help ↩
- Jochen Setzer. (2020). Looker Studio Calculated Fields – The Ultimate Guide ↩
- [Pritom Dey. (2020). ↩
- CASE. Data Studio Help ↩
- CONCAT. Data Studio Help ↩
- HYPERLINK. Data Studio Help ↩
- REGEXP_EXTRACT. Data Studio Help ↩
- REGEXP_MATCH. Data Studio Help ↩
- REGEXP_REPLACE. Data Studio Help ↩
- UPPER. Data Studio Help ↩
- LOWER. Data Studio Help ↩