You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Google Data Studio中复现Google Sheets中的临时同期群分析(注册月份vs购买月份)

Got it, let's walk through how to replicate your ad-hoc cohort analysis in Google Data Studio step by step. I've dealt with similar setups before, so here's a practical breakdown:

Step 1: Prep Your Data Model (Critical First Step)

Since you're working with three separate data sources, you need to tie them together logically. Start by creating a consolidated view in your Google Cloud PostgreSQL instance—this will make Data Studio's work way easier than trying to mix all sources directly in DS.

Here's a SQL script to create a cohort-ready view that combines users and orders:

WITH user_cohorts AS (
  SELECT
    u."User ID",
    -- Format registration date into YYYY-MM cohort group
    TO_CHAR(u."User reg date", 'YYYY-MM') AS cohort_month,
    DATE_TRUNC('month', u."User reg date") AS cohort_start_date,
    -- Count total users per cohort (for later marketing spend calculations)
    COUNT(*) OVER (PARTITION BY TO_CHAR(u."User reg date", 'YYYY-MM')) AS cohort_total_users
  FROM users u
),
order_cohorts AS (
  SELECT
    o."User ID",
    o."Money earned",
    -- Calculate months between registration and order date
    EXTRACT(YEAR FROM o."Payment date") * 12 + EXTRACT(MONTH FROM o."Payment date") 
    - (EXTRACT(YEAR FROM u."User reg date") * 12 + EXTRACT(MONTH FROM u."User reg date")) AS month_offset,
    TO_CHAR(o."Payment date", 'YYYY-MM') AS order_month
  FROM orders o
  JOIN users u ON o."User ID" = u."User ID"
)
SELECT
  uc.cohort_month,
  oc.month_offset,
  SUM(oc."Money earned") AS total_cohort_revenue,
  COUNT(DISTINCT oc."User ID") AS active_users_in_month,
  uc.cohort_total_users,
  uc.cohort_start_date
FROM user_cohorts uc
LEFT JOIN order_cohorts oc ON uc."User ID" = oc."User ID"
GROUP BY uc.cohort_month, oc.month_offset, uc.cohort_total_users, uc.cohort_start_date
ORDER BY uc.cohort_month, oc.month_offset;

This view gives you core cohort metrics: which month users registered, how many months later they placed orders, total revenue per cohort-month, and total users in each cohort.

Step 2: Connect the Marketing Spend Data

Now, bring in your Google Sheets marketing spend table into Data Studio, then use Data Blending to link it with your PostgreSQL cohort view:

  • Set your PostgreSQL cohort view as the Primary Data Source
  • Add the Google Sheets marketing spend table as a Secondary Data Source
  • Define the join condition: cohort_start_date (from primary) = Date (from secondary, since your spend table uses the first day of the month)
  • Make sure both date fields are set to Date type in Data Studio (not text) to avoid mismatches.
Step 3: Build Cohort Calculated Fields in Data Studio

Add these calculated fields to your blended data to get actionable metrics:

  1. Cohort Conversion Rate:
    active_users_in_month / cohort_total_users
    
    (Format as percentage to see what % of the cohort was active each month)
  2. Cohort ROI:
    IFNULL(total_cohort_revenue / "Spend for a month", 0)
    
    (Handles cases where there's no revenue for a cohort-month to avoid errors)
  3. Average Revenue Per Active User (ARPA):
    total_cohort_revenue / active_users_in_month
    
Step 4: Build the Cohort Visualization

The best way to display cohort analysis in Data Studio is with a Heatmap or a Pivot Table:

  • For a Heatmap:
    • Rows: cohort_month (your registration cohorts)
    • Columns: month_offset (0 = registration month, 1 = first month post-reg, etc.)
    • Values: Pick your metric (e.g., total_cohort_revenue or Cohort Conversion Rate)
    • Use conditional formatting to highlight high/low values (makes trends easier to spot)
  • For a Pivot Table:
    • Same row/column setup as the heatmap, but adds exact numeric values for deeper analysis.
Step 5: Validate and Debug

Double-check these to ensure accuracy:

  • Verify that month_offset is calculating correctly: A user who registered in January 2023 and ordered in January should have month_offset = 0, February orders = 1, etc.
  • Confirm marketing spend is tied to the correct cohort: The spend for January 2023 should only link to the January 2023 cohort.
  • Check for nulls: Use IFNULL() in calculated fields to replace empty values with 0 where needed.

内容的提问来源于stack exchange,提问作者Pavel Zagorodnikh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 03:49:08