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

Calculated Field: Count of Sessions when X = Y

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Greetings,

 

I have a session-level custom dimension with a true/false metric that I'd ideally like to visualize as a ratio of sessions.

 

In other words, what percentage of all sessions has custom dimension set as 'true'.

 

I'm really struggling to figure it out on my own.

 

I've started with something like: 

 

case when REGEXP_MATCH(custom_dimension,'true') then count(Sessions) else 0 END

 

But clearly, that doesn't work.

 

Help?

 

Thanks

1 Expert replyverified_user

Re: Calculated Field: Count of Sessions when X = Y

Follower ✭ ☆ ☆
# 2
Follower ✭ ☆ ☆
I would do it in the same way and actually I have a similar issue: https://www.en.advertisercommunity.com/t5/Data-Studio-Reports/Calculated-Field-Conditional-Count-ign...

So I am wondering whether someone can answer yours as well.

Re: Calculated Field: Count of Sessions when X = Y

Explorer ✭ ✭ ✭
# 3
Explorer ✭ ✭ ✭

Hey Mike,

 

Advanced segments will be helpful for this kind of problem. 

 

create a new segment

select conditional segments

select your custom dimension in your ad content field

and input true or false in the empty field. 

 

You can apply this to all reports where you need. Hope this will solve your problem and if not please let me know. Cheers. 

Re: Calculated Field: Count of Sessions when X = Y

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
Hi Mike,

As I have understood that the custom dimension is returning boolean values but as per your expression you converted Boolean data type to string data type. Hence, your expression didn't work. May be you can try without single quotes ('')
or
you can use my solution:
Have you tried with this aspect, sum(case when custom_dimensions =true) then 1 else 0 end)?

I hope this solution will work.

Thanks

Best
Abhishek

Re: Calculated Field: Count of Sessions when X = Y

Google Employee
# 5
Google Employee
Abhishek's proposal should work (except that it has an extra closing parenthesis).

CASE statement can return literals or fields of the datasource. You cannot do calculations inside the THEN clause.

Re: Calculated Field: Count of Sessions when X = Y

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭
Hello Dimitris,

Thanks for for correcting me.

You are right. I didn't see this 'extra closing parenthesis'.

Updated Formula: sum(case when custom_dimensions=true then 1 else 0 end)

Thank you

Best
Abhishek

Re: Calculated Field: Count of Sessions when X = Y

Follower ✭ ☆ ☆
# 7
Follower ✭ ☆ ☆

Re: Calculated Field: Count of Sessions when X = Y

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭

Re: Calculated Field: Count of Sessions when X = Y

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭
Hi Mike,
Have you found a solution that solves your problem? I have the exact same issue, but none of the solutions above worked for me.