'How to count number of sessions by android device in Data Studio?
How to count number of sessions by android device in Data Studio? When I used it's function in data studio:
SUM(
CASE
WHEN REGEXP_CONTAINS(mobile device, '.*Apple.*') THEN sessions
ELSE NULL
END)
But have an error: you can't use aggregates.
What will the correct function look like to get the result I need?
Solution 1:[1]
To simplify, let's first try to count the number of Apple devices vs. non-Apple devices.
tl;dr create a calculated field which equates to Apple when Mobile Device Info contains Apple. Otherwise, it equates to Android. See a working example here.
Steps
- You need to create a calculated field which acts as a dummy dimension.
Field name:
* Mobile Device Platform
(it's helpful to put an asterisk before calculated fields to find them easier in the list)
Formula:
CASE
WHEN REGEXP_CONTAINS(Mobile Device Info,'Apple') THEN 'Apple'
ELSE 'Android'
END
Use the newly created dimension to split the sessions using a table that has
* Mobile Device Platformas the only dimension andSessionsas a metric.Add other conditions in the formula above to capture more nuances in the data. For example:
CASE
WHEN REGEXP_CONTAINS(Mobile Device Info,'Apple') THEN 'Apple'
WHEN REGEXP_CONTAINS(Mobile Device Info,'Huawei') THEN 'EMUI / HarmonyOS'
WHEN REGEXP_CONTAINS(Mobile Device Info,'(not set)') THEN 'Unknown'
ELSE 'Android'
END
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | whitepanda |
