AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Data Studio
4.1K members online now
4.1K members online now
Ask questions about Data Studio
Guide Me
star_border
Reply

Question about Formula in Data Studio

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi, 

 

I have a problem with a calculated field in Data Studio. I have a field "Campaign", the text is build in "Text1 | Text2_Text3 | Text4 | Text5". I want to extract Text2, so i have a separat field with Text2. I used the formula "Regexp_extract(...)" but it didnt work. 

 

So wanted to ask you. Can you tell me the function for my problem? Thanks a lot.

 

Best Regards

 

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Kasim K
June 2017

Re: Question about Formula in Data Studio

[ Edited ]
Explorer ✭ ✭ ☆
# 3
Explorer ✭ ✭ ☆

Given your pattern, try this:

 

REGEXP_EXTRACT('Text1|Text2|Text3|Text4', '^[^|]+\\|([^|]+)')

 

  • ^ = start of string
  • [^|]+ = first sub-string match anything except a |
  • \\| = | has a special meaning in regex (it means "or"), so we need to escape it - usually we need only one \, but for some reason DS insist that we use two... probably because the regex is used as a string before being passed to the real regex engine, so \\| first becomes \| and then is processed
  • ([^|]+) = match the second text, up until the next |

That should do it! I tested and it worked Smiley Happy 

 

 

View solution in original post

Question about Formula in Data Studio

Participant ✭ ✭ ☆
# 2
Participant ✭ ✭ ☆

What dataset are you feeding in? GA? Sheets?

Marked as Best Answer.
Solution
Accepted by topic author Kasim K
June 2017

Re: Question about Formula in Data Studio

[ Edited ]
Explorer ✭ ✭ ☆
# 3
Explorer ✭ ✭ ☆

Given your pattern, try this:

 

REGEXP_EXTRACT('Text1|Text2|Text3|Text4', '^[^|]+\\|([^|]+)')

 

  • ^ = start of string
  • [^|]+ = first sub-string match anything except a |
  • \\| = | has a special meaning in regex (it means "or"), so we need to escape it - usually we need only one \, but for some reason DS insist that we use two... probably because the regex is used as a string before being passed to the real regex engine, so \\| first becomes \| and then is processed
  • ([^|]+) = match the second text, up until the next |

That should do it! I tested and it worked Smiley Happy 

 

 

Question about Formula in Data Studio

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

thanks a lot it worked Smiley Happy