Fraskito
Fraskito

Reputation: 109

Calculated Field by dividing GA4 sessions by 2 in Locker Studio

I am pulling a report from Google Locker studio and I need to divide by 2 the value of the "sessions" metric that has been generated between 2 dates.

I'm talking about the Google Analytics GA4 data source.

The calculated field I am trying to do is with this code. It has to be stupid but I can't find a way to do it.

CASE
  WHEN 
    fecha BETWEEN DATE(2022, 05, 06) AND DATE(2023, 05, 17)
    THEN Sesiones/2
  ELSE Sesiones
END

The error it shows me is this, but I don't think I'm mixing metrics and dimensions, right?

Metrics (aggregated values) and dimensions (non-aggregated values) cannot be applied to calculated fields at the same time.

Upvotes: 0

Views: 305

Answers (1)

DrJay
DrJay

Reputation: 469

As I understand, you want to handle the data correction without affecting your original data.

It would be a good practice to create a new view or property in Google Analytics specifically for this purpose. This way, you can work with the duplicated data separately.

In your new view or property we know you need to create a filter that adjusts the sessions data for your given period by dividing it by 2.

There are a few steps that I’ve put below, the exact steps may vary depending on your specific setup, but hopefully will work as is:

In your Google Analytics account, go to the Admin section,

locate the view (or property) where you want to apply the filter.

Find Filters section then "Add Filter."

Name your filter (e.g., "Sessions Correction").

Choose a Custom Filter Type and under "Filter Field," select the metric "Sessions."

In the Filter Pattern, you can use your regular expression i.e. (5/6/22|5/7/22|...|5/16/23|5/17/23) to match all the dates.

In the "Field A -> Extract A" section, select "Sessions" and set the operation to "Divide."

In "Field B -> Extract B," enter the value "2."

I’m assuming you know how to create your graph which you can do with the corrected data.

Upvotes: 0

Related Questions