How to combine events using a CASE statement in Google Data Studio

Combining Events using CASE statements

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.

WHEN REGEXP_MATCH(Event Action,"Video play|Downloaded File|Click|") THEN "Interactions" 
ELSE "Other" 

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.