Data Explorer - % of active members by month

Hey there to everyone playing and exploring Data Explorer plugin!

Thanks for helping with all the previous questions @michebs . I’ve got one more regarding data explorer queries.

Has someone ever created a query that fetches % of active users by month?

Active means they either liked or replied in some threads in that month, it doesn’t matter how many times but it needs to be at least 1. % is calculated based on the number of all members of the community. So let’s say we have two people who engaged in a month. One liked some post and the other one replied - so it’s two and we divide that by the sum. of all the members we have in our community.


I hope it helps.
It is worth mentioning that the total number of users varies over time, so what is being considered in the query is the cumulative number of users up to the month and year that the action was performed.

WITH tt_users_by_month AS (
        date_part('year', created_at) AS year, 
        date_part('month', created_at) AS month,
        COUNT(*) AS "new_users_month"
    FROM users
    WHERE id > 0
    GROUP BY date_part('year', created_at), date_part('month', created_at)
    ORDER BY date_part('year', created_at) ASC, date_part('month', created_at)

total_users AS (
        SUM(new_users_month) over (ORDER BY year, month rows between unbounded preceding AND current row) AS total
    FROM tt_users_by_month ORDER BY year, month

    date_part('year', ua.created_at) AS year, 
    date_part('month', ua.created_at) AS month,
    TRUNC(COUNT(DISTINCT user_id)::decimal/*100,2) AS "%"
    user_actions ua
INNER JOIN total_users tu ON (date_part('year', ua.created_at) = tu.year AND date_part('month', ua.created_at) = tu.month)
WHERE action_type IN (1,5)
	GROUP BY date_part('year', created_at), date_part('month', created_at), total

Yep totally makes sense! Thanks!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.