Calculated Fields in Google Data Studio – How to Use Text Functions

Written by Michael Wilson

Michael is the Digital Analytics Director at GlowMetrics, implementing complex tracking for our largest clients via Google Tag Manager while leading our wider analytics work across Google Analytics, Data Studio and Optimize.
August 1, 2019

Have you ever set up a report in Google Data Studio and realised your data isn’t as clean as you’d like it to be?

Maybe you’ve used inconsistent naming conventions in some of your campaigns – some are uppercase, and others are lowercase? Perhaps some of your URLs have parameters appended and others don’t? Or maybe you’ve changed your URLs and removed a sub-directory? Or you’ve renamed a sub-directory?

Luckily, we can fix all these issues by creating new Calculated Fields making use of Data Studio’s Text Functions!



If you have a mixture of uppercase and lowercase within the same dimension, you’ll have fragmented data. If we force all the fields to be uppercase or lowercase, we can consolidate your data and clean it up. Whether you want to go UPPERCASE or lowercase is your call – but lowercase is probably easier on the eyes.



Data Studio has a handy ‘UPPER’ function which allows us to do this. In the screenshot below, you can replace ‘Location’ with whichever Dimension you would like to force to uppercase.

Google Data Studio - Forcing Text to Uppercase



Same idea here – this time we use Data Studio’s ‘LOWER’ function. Again, you put the Dimension you’d like to be lowercase where we’ve used ‘Location’ in the example below.

Google Data Studio - Forcing Text to Lowercase



This one is a little more complicated as we’re going to use Data Studio’s REGEXP_REPLACE function. Regular Expressions can be hard to wrap your head around but don’t worry, we’ve got this.

REGEXP_REPLACE(Page, ‘\\?.+’, ”)

There are three parts to the REGEXP_REPLACE function:

– the first part is the Dimension we’re going to use: Page

…because we want to remove Query Parameters from our Page URLs

– the second part is the Regular Expression: ‘\\?.+

This RegEx looks for ‘?’ and anything after it in your Page URL

– the final part is our replacement string: ”

In this case, it’s a blank string because all we want to do is strip the parameters.

Essentially we’re using the REGEXP_REPLACE function to replace something (our parameters) with nothing (a blank string).

Google Data Studio - Stripping Parameters from URLs



This works in exactly the same way as above – we again use Data Studio’s REGEXP_REPLACE function to remove a string of text. In the example below, we use this function to remove the subdirectory ‘category/’ from a URL string.

REGEXP_REPLACE(Page, ‘category/’, ”)

Google Data Studio - Stripping Partial Text from a String



We can also use the REGEXP_REPLACE function in Data Studio to swap out one string of text for another. It works exactly the same as the previous two examples above, except this time, we’re defining a replacement string in the third part of the function, rather than leaving it as a blank string.

In the example below, we switch out ‘category/’ in our Page URL and replace it with ‘features/’

REGEXP_REPLACE(Page, ‘category/’, ‘features/’)

Google Data Studio - Replacing one Text String with Another

Hopefully this guide to using Text Functions in your Calculated Fields allows you to clean up the data in your Data Studio reports!  If you have any issues getting these to work, feel free to leave a comment below or pop us an email – we’re always happy to help.



  1. Sreerej

    how to extract value between two texts in page field in data studio calculated field

    Example : **abcd/collection/collection-name1/**

    I want to extract only “collection-name1” from it.

    • Michael Wilson

      Hi Sreerej,

      You would use something like…

      REGEXP_EXTRACT(Page, ‘/abcd/collection/([^&]+)/.*’)




Submit a Comment

Your email address will not be published. Required fields are marked *

Enjoyed reading this article? Find more like it below…