Calculate aggregate counts on properties

23 views
Skip to first unread message

Cody Caughlan

unread,
Mar 24, 2016, 4:30:08 PM3/24/16
to Keen IO Community
Hi,

My app has the model where a user can create many groups (but capped at 20). 

Each time a user creates a group I emit this Keen metric:

name: groups.created

properties:

- user_id
- group_id
- created_at

The analysis I'm trying to calculate is to show how many users have group-count=1, how many have group-count=2, etc, (up to 20).

As a user adds new groups over time they will have multiple Keen "records" they've emitted. So I realize this is a variable data set (is that the right terminology).

I know how I could calculate this in SQL - the following query would do the trick:

select count(c.cnt) as user_count, c.cnt from
(
  select 
  creator_id, count(*) as cnt
  from groups 
  group by creator_id /* creator_id is the User ID who created the group */
) c 
group by c.cnt


How can I do this in Keen? If need be I can restructure my collections or events. 

Thanks for any guidance.

/Cody Caughlan

Michelle Wetzler

unread,
Mar 24, 2016, 4:32:34 PM3/24/16
to Cody Caughlan, Keen IO Community
Hi Cody -
Just count the number of groups.created, grouped by user_id. That will give you the total number of groups created by each user!

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages