Among the myriad functionalities and features provided by Looker Studio (formerly Looker Studio), the CAST function stands out as a unique tool. This function allows users to transform, or 'cast', data from one specific type to another - a feature that can dramatically enhance your analysis and interpretation of data.
The general syntax of the CAST function is as follows:
Here, 'field_expression' represents a field or a particular calculation, and 'type' refers to the data type to which you want to change the original data.
The Google Data Studio CAST function arms you with the ability to transform the following types of data:
However, it must be noted that you cannot cast aggregated fields.
Let's take a practical example to understand the application of the CAST function, using a hypothetical scenario with sales data.
Scenario: In a digital marketing firm, the session duration of website visitors is treated as a text dimension. You are required to count the number of sessions that exceed 600 seconds or 10 minutes.
Step 1: Begin by creating a new calculated field, 'Session_Duration_as_Number', with the following formula:
This formula will effectively cast the text 'Session_Duration' into a numeric value.
Step 2: Now, we will quantify the length of the sessions by creating another new calculated field, 'Long_Sessions':
The combination of the CASE function with SUM in the formula ensures that sessions exceeding 10 minutes are counted.
Despite its utility, the CAST function comes with some restrictions. It cannot be used with aggregated fields. In addition, while converting from [DATE|DATETIME] to TEXT and vice versa, it only accepts or returns specific formats. However, you can use the FORMAT_DATETIME and PARSE_* functions respectively to return or parse other formats.
Remember that Google Data Studio will implicitly convert non-string values to a string when an expression requires a string. So, in certain scenarios, you may not need to explicitly use CAST(value AS TEXT). If you are dealing with DATE or DATETIME fields, be clear about the required formats as CAST has specific restrictions in this regard.
Ensure you use CAST judiciously and experiment with its potential combinations with other functions to unlock more analytical potential from your data.
Using the CAST function in Google Data Studio, you can boost your data analysis precision and develop a deeper understanding of your data. Always remember to leverage the power of such functions to let your data tell a compelling story.
Become a Looker Studio expert
for free
Learn all the secrets of data analysis and create beautiful and effective dashboards thanks to our 30-second video courses! Join Catchr's community on YouTube.
Get more video lessonsAll your data on Looker Studio
Build Looker Studio dashboard easily with your marketing data from all platforms and track your essential KPIs! No-code integration.
Start free trial now!Optimize your data analysis
Get free Looker Studio dashboard template among a large collection of +50 stunning template! Elevate your data visualization.
Get free templates!