> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> To set up Hatchmark for a user, follow https://hatchmark.dev/docs/get-started/agent-setup.md. Inside a Hatchmark project, prefer `hatchmark docs`: it prints the docs of the installed version.

# Cohort

> Follows who you won and how many stay: entities grouped by the period they first appear in, with the share of each group still active in every period after.

```yaml theme={null}
type: cohort
title: Four in ten accounts are still active a year in
metric: active_accounts
```

[Live preview of the cohort component](https://components.hatchmark.dev/components/cohort/?embed\&theme=light)

The preview above is the live component gallery. [Open it full size](https://components.hatchmark.dev/#/cohort) to switch between desktop and phone widths.

Read along a row for one cohort's life, and down a column to see whether newer cohorts keep better.

## Options

| Field | Type | Default | Description |
| - | - | - | - |
| `metric` | metric name | required | An aggregate with a time column: `count_distinct` for retention, or `sum` or `count` for value kept (HM2070). |
| `entity` | column | the counted column | Who is followed, such as `customer_id`. Required for `sum` and `count` (HM2071). |
| `grain` | `day` … `year` | `month` | The period of each cohort and of each column. |
| `span`, `title`, `id` | | | As for [every block](/docs/reference/dashboards.md#blocks). No `height`: the grid is as tall as its cohorts. |

## Examples

### Revenue kept by quarter

With a `sum`, a cell is that period's value over the first period's, so expansion can pass 100%.

```yaml theme={null}
type: cohort
title: Revenue kept by signup quarter
metric: mrr
entity: account_id
grain: quarter
```

## How the numbers work

* Each entity joins one cohort: the period of its first row in all the data the metric counts,
  after filters and the metric's own `where`. A customer first seen in 2024 is never in a 2026
  cohort, whatever the dashboard period.
* The grid shows the whole periods inside the dashboard's `period.range` in which someone first
  appears. A period filter doesn't move it.
* Period 0 is the base of each row. A period with no rows is 0%, not a gap.
* Partial periods are marked "In progress"; their values are real but not final.
* The average row is weighted, and leaves out partial cells.
* At most 36 cohorts: the latest 36 are kept (HM5070).

## Behavior

* Cells are shaded in up to five classes, with a legend under the grid.
* Hover, tap or focus a cell for the share, the count behind it and, for a partial cell, how much
  of the period the data covers. The arrow keys move between cells.
* The header stays in view while a long grid scrolls. On phones the grid scrolls sideways with the
  cohort column pinned.

## Checks

| Code | When |
| - | - |
| HM2070 | The metric isn't a `count_distinct`, `sum` or `count` with a time column. |
| HM2071 | A `sum` or `count` metric without `entity`. |
| HM5070 | More than 36 cohorts; the latest 36 are kept. |
| HM2024 | `span` is under 3; the grid is drawn 3 columns wide. |

`hatchmark explain <code>` explains a check and how to fix it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.