Haisenbergretention-rate
    Updated 2025-03-29
    -- Step 1: Create CTEs to identify active users for each month

    WITH monthly_active_users AS (
    SELECT DISTINCT
    date_trunc('month', block_timestamp) AS month,
    sender AS address
    FROM
    aptos.core.fact_transactions
    WHERE
    block_timestamp >= DATE_TRUNC('month', CURRENT_DATE) - INTERVAL '13 months'
    ),

    -- Step 2: Calculate retained users
    retained_users AS (
    SELECT
    current_month.month,
    COUNT(DISTINCT current_month.address) AS total_users,
    COUNT(DISTINCT previous_month.address) AS retained_users
    FROM
    monthly_active_users current_month
    LEFT JOIN
    monthly_active_users previous_month
    ON current_month.address = previous_month.address
    AND current_month.month = previous_month.month + INTERVAL '1 month'
    GROUP BY
    current_month.month
    )

    -- Step 3: Calculate retention rate
    SELECT
    month,
    total_users,
    retained_users,
    CASE
    WHEN LAG(total_users) OVER (ORDER BY month) IS NULL THEN NULL
    ELSE (retained_users * 100.0 / LAG(total_users) OVER (ORDER BY month))
    Last run: about 2 months ago
    MONTH
    TOTAL_USERS
    RETAINED_USERS
    RETENTION_RATE
    1
    2024-02-01 00:00:00.00015659520
    2
    2024-03-01 00:00:00.000250734750521532.262483
    3
    2024-04-01 00:00:00.000188277451827720.670334
    4
    2024-05-01 00:00:00.000160732230906916.415619
    5
    2024-06-01 00:00:00.000392250443442827.028063
    6
    2024-07-01 00:00:00.000270376060120415.327046
    7
    2024-08-01 00:00:00.000304392972054526.64974
    8
    2024-09-01 00:00:00.000403199594304830.981275
    9
    2024-10-01 00:00:00.0008117692136448233.841361
    10
    2024-11-01 00:00:00.0008263438292253136.001994
    11
    2024-12-01 00:00:00.00010353849338957941.018992
    12
    2025-01-01 00:00:00.00016039066423777540.929465
    13
    2025-02-01 00:00:00.00015144585386345724.087793
    14
    2025-03-01 00:00:00.00013220313427026628.196652
    14
    742B
    193s