Back to Supabase in Google Sheets
SheetXAI logo
Supabase logo
Supabase · Google Sheets Guide

Run a Cohort Retention SQL Query on Supabase and Pull Results Into Google Sheets

2026-05-13
4 min read
See the Excel version →

The Scenario

You are a growth analyst at a B2B SaaS startup. It is Tuesday at 4 PM and your head of growth wants a cohort retention table in a Google Sheet by end of day so she can build the board deck tonight.

The data is in your Supabase database: a users table and an events table. You need retention by cohort week — how many users who signed up in week 1 came back in week 2, week 3, and so on. Twenty-six cohorts, six weeks of data each.

The bad version of this afternoon:

  • You message the backend engineer to ask for database credentials
  • He sends a read-only connection string an hour later
  • You open DBeaver, configure the connection, write the query
  • The query runs but the column names are cnt and wk — you rename them
  • You copy the result, paste it into a sheet, realize the formatting is wrong
  • You spend 20 minutes cleaning the date columns
  • It is 6:15 PM. She needed it at 5:30.

The fast version is one prompt.

The Easy Way: One Prompt in SheetXAI

SheetXAI is an AI agent inside your spreadsheet that reads the sheet and runs the Supabase query for you, so you do not need to touch DBeaver or ask engineering for credentials.

Open the SheetXAI sidebar and type:

Run this SQL against my Supabase project abc123: SELECT cohort_week, week_number, COUNT(DISTINCT user_id) AS retained_users FROM cohort_retention_view GROUP BY cohort_week, week_number ORDER BY cohort_week, week_number — write the results into this sheet starting at A1. Add a header row with readable column names: Cohort Week, Week Number, Retained Users.

SheetXAI calls Supabase, runs the query, and writes the result table into the sheet — header row included, column names readable, data starting at A1.

What You Get

A formatted retention table ready for analysis:

  • Header row — Cohort Week, Week Number, Retained Users
  • One row per cohort-week intersection — sorted chronologically
  • Clean date values — no epoch integers, no timezone offsets

You did not touch a database client or ask anyone for credentials. The analyst has what she needs. The board deck gets built tonight.

Want a different shape? Tell SheetXAI to pivot the table — cohorts as rows, week numbers as columns — and it restructures the output inline.

What If the Data Is Not Quite Ready

Most production Supabase databases are not as tidy as a pre-built view. SheetXAI can do cleanup, reshaping, and analysis in the same prompt.

When you need to write the join yourself

You do not have a cohort_retention_view — you just have raw users and events tables.

Run a SQL query on Supabase project abc123 that calculates cohort retention. Cohort week is the week_of_year of the user's created_at in the users table. Retention is based on whether the user has a login event in the events table in each subsequent week. Write results into this sheet as Cohort Week, Week Number, Retained Users.

When the result has timestamps instead of week labels

The raw query returns epoch integers or ISO timestamps for cohort dates.

Run the cohort SQL on Supabase project abc123 and write results into this sheet. Convert all cohort_week values from epoch milliseconds to a readable date like "2026-W01" before writing them into the sheet.

When you only want the last 8 cohorts

The full dataset has two years of cohorts and you only need recent ones for the board deck.

Run the cohort retention query on Supabase project abc123 — filter to cohorts that started in the last 8 weeks only. Write results into this sheet sorted oldest cohort first.

When you need the data cleaned, pivoted, and annotated in one shot

Raw join results, a pivot table, and a summary annotation — all in one go.

Run a cohort retention SQL on Supabase project abc123 joining the users and events tables. Filter to the last 12 cohorts. Write the raw results into the Raw tab. Then pivot the data — cohort weeks as rows, week numbers as columns, retained user counts as values — and write the pivot into the Pivot tab. In cell A1 of the Summary tab, write one sentence describing the strongest and weakest cohort based on week-4 retention.

The pattern: instead of querying then cleaning then reshaping, you ask for all of it in one prompt. SheetXAI handles the conditional logic inline.

Try It

Get the 7-day free trial of SheetXAI and open any Google Sheet, then ask it to run a SQL query against your Supabase project. The Supabase integration is included in every SheetXAI plan. For related workflows, see how to run a product analytics snapshot query or the Supabase in Google Sheets overview.

Stop memorizing formulas.
Tell your spreadsheet what to do.

Join 4,000+ professionals saving hours every week with SheetXAI.

Learn more