# Cohorts (/docs/people/cohorts)

A cohort is a named group of people, such as *power users*, *new users*, *enterprise accounts* or *repeat customers*. Define it once and reuse it everywhere: as a filter, a breakdown, a flag target or an experiment segment.

| | Dynamic | Static |
| --- | --- | --- |
| Who's in | Everyone who matches your rules | A fixed list you add people to |
| Changes on its own | Yes. People join and leave as they behave. | No |
| Good for | "Ordered at least twice in 90 days" | Beta testers, a list from sales |

You choose the type when you create the cohort, and you can't change it later.

## Build a dynamic cohort [#build-a-dynamic-cohort]

**People → Cohorts → New cohort.** Name it, keep the type on **Dynamic**, and choose whether people must match **All** or **Any** of your rules. Rules come in three kinds:

- **Person property**: *country equals DE*, *plan is one of pro, business*, *company_size is set*.
- **Behaviour**: *performed* (or *did not perform*) an event *at least N times in the last N days*. Click **Total of a property** to add a sum, such as *total `amount` ≥ 500*. You can also limit which events count, such as only `currency = EUR`.
- **Cohort**: *in* or *not in* another cohort.

Save with **Create cohort** (or <kbd>⌘S</kbd>). The size panel shows how many people match and when it was counted. Click recalculate to refresh it.

Some examples:

| Cohort | Rules |
| --- | --- |
| Power users | Performed `project_opened` at least 20 times in the last 14 days |
| New users | Performed `signed_up` in the last 7 days |
| Repeat customers | Performed `order_completed` at least 2 times in the last 90 days |
| Big spenders | Performed `order_completed` with total `amount` ≥ 500 in the last 90 days |
| Lapsed customers | Performed `order_completed` in the last 365 days, **and** did not perform it in the last 60 days |
| Enterprise accounts | Person property `plan` equals `enterprise` |

Time windows are counted back from today, so membership changes over time. A power user who stops logging in drops out after 14 days.

Combine cohorts to keep rules short. For example, build *New power users* as *in Power users* **and** *in New users*. A cohort can't include itself.

## Build a static cohort [#build-a-static-cohort]

Choose **Static** when you create it, and paste the initial members: one email or id per line. You can paste a spreadsheet column, because commas and tabs also work. People who can't be found are skipped.

Later, use **Add people** to paste more, remove people from the member list, or click **Add to cohort** on someone's profile.

## Build a cohort from SQL [#build-a-cohort-from-sql]

When a rule is easier to say in SQL, write it once in the [SQL editor](/docs/product-analytics/sql) and save it. The query needs a `person_id` column:

```sql
SELECT person_id
FROM events
WHERE event = 'order_completed'
GROUP BY person_id
HAVING count() >= 3 AND max(timestamp) > now() - INTERVAL 30 DAY
```

Then either choose **SQL** when you create a cohort and pick the query, or open the query and use **⋯ → Use with people → Create cohort**. Members are the people the query returns. They're recalculated every hour, whenever the query changes, and when you click recalculate. A SQL cohort works everywhere other cohorts do.

## Use a cohort [#use-a-cohort]

| Where | How |
| --- | --- |
| Insights | **Analyse** on the cohort page opens a trend for its members. In any insight, filter by cohort or break down by cohorts to compare them. |
| Agents | Ask about one cohort, for example *"which pages do repeat customers land on?"* Agents can filter any query, including web analytics, by cohort. |
| Feature flags | Target a flag at the cohort, or at everyone *not* in it. See [Feature flags](/docs/feature-flags#who-gets-it). |
| Experiments | Report results per cohort. See [Segments](/docs/experiments/results#segments). |
| Feedback | Read only what one cohort is saying. |
| People | Filter the persons list to the cohort. |

Editing a cohort's rules applies everywhere from the next chart on. Flags pick up membership changes within about five minutes.

## Delete a cohort [#delete-a-cohort]

Use the **⋯** menu. A cohort that an experiment reports on can't be deleted, so remove it from the experiment first. Filters and flag rules that used a deleted cohort match nobody.
