Understanding Functions in Google Data Studio

Functions in Google Data Studio are formulas which are used to: 

  • aggregate data. 
  • do mathematical calculations on your data.
  • manipulate time data. 
  • manipulate geographic location data. 
  • manipulate string data. 

 

Functions make your calculated fields more powerful. They are used inside of calculated fields as a formula.

If you remember, we used the ‘CASE’ function as a formula when dealing with boolean values:

‘CASE’ is just one of the many functions provided by Google Data Studio.

Google data studio provides over 50 functions that you can use inside of calculated fields as a formula.

 

Following are the typical attributes of a function in Google Data Studio

  1. Every function in data studio has some purpose. 
  2. Every function in data studio has syntax
  3. All functions expect one or more parameters
  4. Parameters are listed in the syntax
  5. All functions return a value
  6. Almost all functions have certain restrictions regarding how they can be used.

 

#1 Every function in data studio has some purpose

For example, ‘CASE’ function is used to create new fields that use conditional logic to determine the field values.

‘AVG’ function is used to calculate the average value of a numeric field.

Similarly, ‘COUNT’ function is used to count the number of items in a field.

Note: You can learn more about the purpose of each function from the Google help documentation on each function: https://support.google.com/datastudio/topic/7019880?hl=en&ref_topic=7570421   

 

#2 Every function in data studio has syntax

Syntax defines how a function must be used. It defines how parameters (more about them later) must be used. 

 

For example, following is the syntax for the CASE function:

CASE

    WHEN condition THEN result

    WHEN condition THEN result

    WHEN condition THEN result

    … 

    ELSE result 

END

 

Following is the syntax for ‘AVG’ function:

AVG(value)

 

Following is the syntax for ‘COUNT’ function:

COUNT(value)

 

Note: You can learn more about the syntax of each function from the Google help documentation on each function: https://support.google.com/datastudio/topic/7019880?hl=en&ref_topic=7570421   

 

#3 All functions expect one or more parameters

Parameters (also called ‘arguments’) are the input a function expect in Google data studio. 

The parameter tell the function what data to act upon. 

Parameters can be field names or expressions. 

An expression can be a number, literal text, or a statement that evaluates to a field name in your data source. 

Parameters can also provide additional instructions or formatting information.

For example, CASE function expect following parameters:

  1. Condition
  2. Result
  3. Else result

 

#1 Condition—It is an expression which evaluates to a boolean value (true or false). Conditions can include dimensions or metrics but not both:

#2 Result – the value to return. It can be a dimension, metric, or literal value:

#3 ELSE result (optional) – It is the default value to return if no other condition is met.

 

Note(1): When providing parameters, be sure to enclose literal text in single or double quotes.

Note(2): You can learn more about the parameters used by each function from the Google help documentation on each function: https://support.google.com/datastudio/topic/7019880?hl=en&ref_topic=7570421   

Note(3): You can click on the ‘Format Formula’ button, to make your formula more readable.


#4 Parameters are listed in the syntax

All the parameters which the CASE function expect, are listed in the syntax of the CASE function:

 

CASE

    WHEN condition THEN result

    WHEN condition THEN result

    WHEN condition THEN result

    … 

    ELSE result 

END

So if you remember the syntax, you would remember how to use the CASE function.

 

#5 All functions return a value

For example ‘CASE’ function returns dimensions or metrics based on conditional expressions.

The ‘AVG’ function returns the average for all values in a field or expression.

Similarly, the COUNT function returns the total number of items in a field or expression.

Note: You can learn more about the values returned by each function from the Google help documentation on each function: https://support.google.com/datastudio/topic/7019880?hl=en&ref_topic=7570421   

 

#6 Almost all functions have certain restrictions regarding how they can be used.

For example, when using the CASE function you can not compare dimensions to dimensions or metrics to metrics:

In data studio you can compare a dimension or metric only with a literal value. 

Similarly, you can not apply the AVG function or COUNT function to a pre-aggregated field.

Note: You can learn more about such restrictions on each function from the Google help documentation on each function: https://support.google.com/datastudio/topic/7019880?hl=en&ref_topic=7570421   

 

More information on each function, including examples, is also available in the formula editor.

When you type a function name in the formula editor, data studio provide information about the function like its syntax, its purpose and its use case:

The bottom of the formula editor sometimes provides additional information about how a function is being used and how it should be used.  

For example, in the screenshot above, data studio was expecting arguments (Expected arguments, but none were provided).

 

Types of data studio functions

All of the data studio functions are grouped into following categories:

  1. Aggregation functions
  2. Arithmetic functions
  3. Date functions
  4. Geo functions
  5. Text functions
  6. Miscellaneous functions

 

Aggregation functions

These functions are used to aggregate data. 

Following are examples of aggregation functions:

  1. APPROX_COUNT_DISTINCT
  2. AVG
  3. COUNT
  4. COUNT_DISTINCT
  5. MAX
  6. MEDIAN
  7. MIN
  8. PERCENTILE
  9. STDDEV
  10. SUM
  11. VARIANCE

Note: Aggregation functions can not be applied to already aggregated data. This includes most metrics found in Google Analytics and Google Ads. For example, Sessions is already summed in your data set, so the formula SUM(Sessions) will produce an error.

 

Arithmetic functions

These functions are used to do mathematical calculations on your data.

Following are examples of Arithmetic functions:

  1. NARY_MAX
  2. ACOS
  3. ATAN
  4. ABS
  5. COS
  6. FLOOR
  7. LOG
  8. LOG10
  9. ASIN
  10. NARY_MIN
  11. POWER
  12. ROUND
  13. SIN
  14. SQRT
  15. TAN
  16. CEIL

 

Date functions

These functions are used to manipulate time data. 

Following are examples of Date functions:

  1. DATE_DIFF
  2. DAY
  3. HOUR
  4. MINUTE
  5. MONTH
  6. QUARTER
  7. SECOND
  8. TODATE
  9. WEEK
  10. WEEKDAY
  11. YEAR
  12. YEARWEEK

 

Note: Date functions assume UTC as their timezone. Date functions can optionally take either an input or output (or both) format string.

Geo functions

These functions are used to manipulate geographic location data. 

Following are examples of Geo functions:

  1. TOCONTINENT
  2. TOCOUNTRY
  3. TOREGION
  4. TOSUBCONTINENT

 

Text functions

These functions are used to manipulate string data. 

Following are examples of text functions:

  1. CONCAT
  2. CONTAINS_TEXT
  3. ENDS_WITH
  4. LEFT_TEXT
  5. LENGTH
  6. LOWER
  7. REGEXP_EXTRACT
  8. REGEXP_MATCH
  9. REGEXP_REPLACE
  10. REPLACE
  11. RIGHT_TEXT
  12. STARTS_WITH
  13. SUBSTR
  14. TRIM
  15. UPPER

 

Miscellaneous functions

Functions which do not fall in any of the below categories come under the ‘Miscellaneous functions’ categories:

  1. Aggregation functions
  2. Arithmetic functions
  3. Date functions
  4. Geo functions
  5. Text functions

Following are the examples of Miscellaneous functions:

  1. CASE
  2. CAST
  3. HYPERLINK
  4. IMAGE

 

Related Articles

 

Do you know the difference between Digital Analytics and Google Analytics?


99.99% of course creators themselves don’t know the difference between Digital analytics, Google Analytics (GA) and Google Tag Manager (GTM).

So they are teaching GA and GTM in the name of teaching Digital analytics.

They just copy each other. Monkey see, monkey do.

But Digital analytics is not about GA, GTM.

It is about analyzing and interpreting data, setting up goals, strategies and KPIs.

It’s about creating strategic roadmap for your business.


Digital Analytics is the core skill. Google Analytics is just a tool used to implement ‘Digital Analytics’.

You can also implement ‘Digital analytics’ via other tools like ‘adobe analytics’, ‘kissmetrics’ etc.

Using Google Analytics without the good understanding of ‘Digital analytics’ is like driving around in a car, in a big city without understanding the traffic rules and road signs.

You are either likely to end up somewhere other than your destination or you get involved in an accident.


You learn data analysis and interpretation from Digital analytics and not from Google Analytics.

The direction in which your analysis will move, will determine the direction in which your marketing campaigns and eventually your company will move to get the highest possible return on investment.

You get that direction from ‘Digital analytics’ and not from ‘Google Analytics’.


You learn to set up KPIs, strategies and measurement framework for your business from ‘Digital analytics’ and not from ‘Google Analytics’.

So if you are taking a course only on 'Google Analytics’, you are learning to use one of the tools of ‘Digital analytics’. You are not learning the ‘Digital analytics’ itself.

Since any person can learn to use Google Analytics in couple of weeks, you do no get any competitive advantage in the marketplace just by knowing GA.

You need to know lot more than GA in order to work in digital analytics and marketing field.


So what I have done, if you are interested, is I have put together a completely free training that will teach you exactly how I have been able to leverage digital analytics to generate floods of news sales and customers and how you can literally copy what I have done to get similar results.

Here what You'll Learn On This FREE Web Class!


1) The number 1 reason why most marketers and business owners are not able to scale their advertising and maximise sales.

2) Why you won’t get any competitive advantage in the marketplace just by knowing Google Analytics.

3) The number 1 reason why conversion optimization is not working for your business.

4) How to advertise on any marketing platform for FREE with an unlimited budget.

5) How to learn and master digital analytics in record time.

 
 

My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

Himanshu Sharma

Digital Marketing Consultant and Founder of Optimizesmart.com

Himanshu helps business owners and marketing professionals in generating more sales and ROI by fixing their website tracking issues, helping them understand their true customers purchase journey and helping them determine the most effective marketing channels for investment.

He has over 12 years experience in digital analytics and digital marketing.

He was nominated for the Digital Analytics Association's Awards for Excellence.

The Digital Analytics Association is a world renowned not-for-profit association which helps organisations overcome the challenges of data acquisition and application.

He is the author of four best-selling books on analytics and conversion optimization:

error: Alert: Content is protected !!