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

CASE WHEN syntax error(Invalid formula.)

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi all :

I made a new dimension

 

CASE 
  WHEN REGEXP_MATCH(SUBSTR(deviceName , 1, 7), "Samsung")
    THEN "Samsung"
  ELSE
    deviceName
END

 

I would like to check the value of "deviceName", if SUBSTR(deviceName, 1, 7) equals "Samsung" then show "Samsung", otherwise show it's original value.

But Compiler shows it's Invalid formula.

I am no sure where going wrong, if anyone can help that would be much appreciated.

 

Thanks

Mickey

1 Expert replyverified_user

CASE WHEN syntax error(Invalid formula.)

Top Contributor
# 2
Top Contributor

Hi @宜宏 賴 the deviceName is another custom field or an existing GA dimension?

 

Web analyst @ escapestudio.net

CASE WHEN syntax error(Invalid formula.)

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

It's a custom field.

 

Marked as Best Answer.
Solution
Accepted by topic author 宜宏 賴
October 2016

CASE WHEN syntax error(Invalid formula.)

Follower ✭ ✭ ✭
# 4
Follower ✭ ✭ ✭

The CASE function can't return metric or dimension values, unfortunately.

 

It has to be a string, number, or boolean. 

 

So you would have to make a rule for every device type grouped or individually and do ELSE "Uncategorized" or something of the like. 

 

This thread might be helpful: https://www.en.advertisercommunity.com/t5/Data-Studio-Reports/Calculated-Field-Conditional-Count-ign...

 

CASE WHEN syntax error(Invalid formula.)

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

I got it.

Thanks so much.

 

CASE WHEN syntax error(Invalid formula.)

[ Edited ]
Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

But why this still have invalid formula?

 

CASE WHEN REGEXP_MATCH(SUBSTR(deviceName, 1, 7), "Samsung") THEN "Samsung" ELSE "Others" END

CASE WHEN syntax error(Invalid formula.)

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

Hi Mickey

 

Will this do for you:

 

CASE WHEN REGEXP_MATCH(deviceName, "^Samsung.*") THEN "Samsung" ELSE "Other" END

 

Cheers

Sandro