The Scenario
A lifecycle marketing analyst took over the in-app messaging program last month after the previous person left. In their handoff notes was a spreadsheet titled "Cohort Definitions" — 10 rows, each with a segment name and a behavioral filter description. The problem: none of those cohorts exist in PostHog yet. The previous person was building them manually, one at a time, and only got through the first three before leaving. Now there's a campaign that depends on all 10 being live, and it's supposed to launch in two days.
The bad version:
- Open PostHog's cohort creation UI, enter the first cohort name, click "Add filter," choose filter type, set property name, set condition, set value, save — then repeat nine more times
- Realize mid-way that the filter definitions in the spreadsheet are written in plain English ("users who completed onboarding but haven't made a purchase in 30 days") and you need to translate each one into PostHog's filter schema before the UI will accept it
- Create all 10 cohorts, go to set up the campaign, discover that cohort 7 has a filter typo that the UI accepted but PostHog rejects during evaluation — so none of the users in that segment will match
Creating 10 cohorts by hand from a definition doc is the kind of work that compounds: every translation error propagates into the campaign targeting.
The Easy Way: One Prompt in SheetXAI
SheetXAI is an AI agent inside your Google Sheet. It reads your cohort definition table, translates filter descriptions into PostHog's expected format, creates each cohort via the API, and writes the returned cohort IDs back into the sheet.
Create a PostHog project cohort for each row in the 'Cohort Definitions' sheet — cohort name in column A, filter JSON in column B — and write the returned cohort ID into column C.
What You Get
- PostHog creates one cohort per row using the name and filter definition from the sheet
- Column C receives the PostHog-assigned cohort ID for each row — you have a reference for every cohort you can use immediately in campaign setup
- Rows that fail are noted with the specific API error in column C so you can fix and re-run only those
What If the Data Is Not Quite Ready
Filter definitions are in plain English, not JSON
For each row in the 'Cohort Definitions' sheet, interpret the behavioral description in column B as a PostHog cohort filter (event-based or property-based), create the cohort with name from column A, and write the returned cohort ID into column C. Write the interpreted filter JSON into column D so I can review it.
You want to export cohort membership after creation
For cohort ID 4521, retrieve the list of persons in that cohort and write each person's distinct_id and email (if available) into columns A and B of the 'Cohort Export' sheet. Write the total count at the bottom of column A.
Some cohorts already exist and you want to skip them
Before creating cohorts from the 'Cohort Definitions' sheet, check if a cohort with the same name already exists in PostHog. For existing cohorts, write the existing cohort ID into column C and skip creation. For new cohorts, create them and write the new ID into column C.
End-to-end: create all cohorts, verify member counts, flag empties
Create a PostHog cohort for each row in the 'Cohort Definitions' sheet using name from column A and filter JSON from column B. Write cohort IDs into column C. Then for each created cohort, fetch the member count and write it into column D. In column E, write "Empty cohort - check filter" for any cohort with a member count of zero.
One prompt to build the cohorts and immediately validate they're working.
Try It
Get the 7-day free trial of SheetXAI and open any Google Sheet where you've drafted your segmentation definitions, then ask it to create the PostHog cohorts. Related: Bulk Add Users to a PostHog Static Cohort From a Google Sheet and the PostHog hub.
