Recently I was working with a data source in Google Data Studio that needed a bit of tidying up. It was actually Google Analytics data, and the Event Action contained the html entities & and ' which needed to be replaced with the & and ' characters respectively.
I knew how to replace either one of those values using a calculated field:
REPLACE(Event Action,"&","&")
But how should I tackle the second replace? Well, one approach would be to create a second calculated field that uses my first calculated field as the input:
REPLACE(My Example Field,"'","'")
That works fine for two replaces, but what if I needed to make 20? Or 50? The more replaces I need, the less feasible it becomes to create and maintain a calculated field for each step.
The good news is that it is possible to nest REPLACE functions (and other functions) in Google Data Studio. So instead of the two-step process above, I could just use the following formula:
REPLACE(REPLACE(Event Action,"&","&"),"'","'")
So you can see that within the one formula, the output of the & REPLACE then becomes the input for the ' REPLACE.
This seems pretty straightforward, but I couldn't find it documented anywhere on Data Studio Help so I thought I would share.
Brilliant!
I used it to nest 6 levels and it works flawlessly.
Thanks James, you saved my day 🙂
Gonzo
Best Tip ever 🙂
Didn't get it in a rush. Your formula makes so much sense!
Alex