Skip to content
Advertisement

Counting users based on an event count

I have an events table where I currently have a count of users grouped by the date. I am wanting to make two different counts based on the number of times a user had a specific event (we’ll call it event_a) The first count will count the user if event_a appeared exactly 1 time for the user, the 2nd count will count the user if the event_a appeared more than once for the user.

I believe to achieve this I need a CASE WHEN, but I am unsure how to correctly write the code to give me the output I need. Currently this is what I have:

When I run this code I get the error message:

Query 1 ERROR: ERROR: Invalid input syntax for integer: “event_a”

Looking at my code and the error, it makes sense why I am seeing this error because I am trying to use a mathematical operation on a string. I believe I need to have some type of count within my count syntax, but I am unsure how to approach that. Am I on the right track, or is there a different way to approach this??

Advertisement

Answer

Use two levels of aggregation, one at the date/user level and the other just for the date:

EDIT:

You can replace the FILTER with:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement