How to combine events using a CASE statement in Google Data Studio
Let’s say we want to combine certain event completions in Google Data Studio.
We might try and use the same formulas that we use for combining goal completions together into custom metrics.
For example this formula below.

However, we are unable to do this for events. A solution is to use a CASE statement to create a custom dimension for our selected events.

Let’s say we only want to track Video play, Downloaded File and Click Event Actions for a time period. We want the sum of these events to be known as ‘Interactions’.
The total number of Interactions for the time period is 38 (22+11+5). There that’s the number we need to display as Interactions on our Data Studio report.
We can use the CASE statement below to add the various actions together.
CASE
WHEN REGEXP_MATCH(Event Action,"Video play|Downloaded File|Click|") THEN "Interactions"
ELSE "Other"
END
We now have our Interactions as a dimension in our report.

We have our Total Events as 232. We want to filter this to only include our Interactions.

We do this by creating a Filter for our Scorecard chart.

We create the filter to only include ‘Interactions’ that contain ‘Interactions’. So this will display only events that are included as part of our Interactions custom field.

We know have the result we expect and want. Only our Interaction events tracked. The result is 38, the number we were expecting.

We can rename ‘Total Events’ to Interactions for this scorecard.

We can also use the Filter on another chart to give us a breakdown of the Interactions as Event Actions.
Let’s create a bar chart to show the breakdown of interactions.

Below is a breakdown of our Interactions by their Event Actions.

We now have a total of the Interactions, and a breakdown in a chart.
Below is the Data Studio Report.
My Other Blog Posts
Thanks for reading this article. You might enjoy these other posts!
Hello thank you for this tutorial. I tried using the formula you provided but replaced the event action with event category. Unfortunately, I am getting “invalid formula”. Can you take a look at my formula and let me know if I am doing something wrong here.
CASE
WHEN REGEXP_MATCH(Event Category,”Definition Report Window|Reference Report Window|”) THEN “Reports Opened”
ELSE “Other”
END
I’ve just tried it and it says formula is valid.
Are you making sure to replace the ” symbols?
When I copy pasted your CASE statement those gave issues. Might be to do with font on this site.
But I copy pasted, changed ” symbols, and it says its valid.
Need to remove the training pipeline | from your REGEXP_MATCH statement. Can never finish a statement with pipeline (or condition)
[…] Source: Michael Howe-Ely […]