# Historical Count, part 2: Order of operations

> For AI agents: a documentation index is available at [/docs/llms.txt](/docs/llms.txt). Append `.md` to any page URL for markdown, or send `Accept: text/markdown`.

Amplitude's Historical Count filter runs after every other filter in a chart query, which changes which events count toward a user's _N_th occurrence. Part 2 of this 3-part series covers where Historical Count sits in Amplitude's filter order of operations, how it differs from Event Historical Count (which runs first), and how it interacts with custom events.

Use Historical Count when you want the _N_th instance that survives your other filters, such as the third event triggered in Germany. Use Event Historical Count when you want the _N_th instance overall, before location, property, or segment filters narrow the result. For the filter's definition and basics, start with [part 1](https://amplitude.com/docs/analytics/historical-count-1).

> **Note:**
>
> This article is second in a series about Historical Counts. If you haven't done so already, read [Historical Count, part 1: Track user behavior for different instances of each user action](https://amplitude.com/docs/analytics/historical-count-1).

## Historical Count in the Amplitude order of operations

Whenever Amplitude applies filters to an event (including filters in segments), it does so in a specific order. **Amplitude always applies the Historical Count filter last**.

Consider the following example.

With the Historical Count filter applied, this chart doesn't show everyone whose third time triggering that event happened in Germany. Instead, it shows the third Germany-located instance of that event. Both previous instances also took place in Germany. The event could be the user's third, eighth, or hundredth time performing that event overall, as long as it was their third Germany-located instance.

> **Note:**
>
> Any group-bys apply to the first event selected in the Funnel Analysis, Pathfinder, and Retention Analysis charts. When you apply a group-by, Amplitude shows the user's property value at the time the user triggers the event for the Nth time.

## Event Historical Count

The Event Historical Count filter works similarly to the Historical Count filter. While both capture a user's _N_th instance of performing a specified action, Amplitude applies Historical Count **after** all other filters. By contrast, Amplitude applies Event Historical Count **first**, **before** any other filters.

This can have important implications for your analyses. Let's use the table below to illustrate the difference:

| **Time** | **Maya’s event** | **Loc’s event** |
| --- | --- | --- |
| 1 | run |  |
| 2 | walk | walk |
| 3 |  | run |

If you set up an event segmentation analysis that searches for `Any Event` where:

- `Historical Count` = `1st`.
- `Event Name` = `Run`.

This yields two results: Maya at time 1, and Loc at time 3.

> **Note:**
>
> While you can use "Any Event" or "Any Active Event" with Historical Count in Event Segmentation charts, you can't use these event types with Historical Count when creating dynamic cohorts in Cohort Builder. If you create a cohort using "Any Event where Historical Count = 1", it becomes a static cohort rather than a dynamic one.

By contrast, consider a similar analysis that searches for `Any Event` where:

- `Event Historical Count` = `1st`.
- `Event Name` = `Run`.

This gives you only one result: Maya at time 1. This is because `Run` is Loc's **second** event, and the Event Historical Count filters out everything but first events.

## Historical Count and custom events

Amplitude considers the custom event logic before the Historical Count filter and counts all underlying events triggered by the user.

For example, imagine a `custom_event_c` that fires when a user triggers **either** `event_a` **or** `event_b`. Let's say that the user triggers events on the following days:

**Day 1:** `event_a`

**Day 3:** `event_b`

**Day 7:** `event_b`

**Day 14:** `event_a`

If you apply the Historical Count filter of 1 to `custom_event_c` within the time frame, Amplitude counts the user in the data point for **Day 1** because the user triggered `event_a` for the first time on that day. Amplitude doesn't count the user's events triggered on **Day 3**, **7**, and **14** for those days.

When you apply the Historical Count filter of 2 for `custom_event_c`, Historical Count registers **Day 3** as the day `custom_event_c` fired for the second time.

Continue to the third article in the Historical Count series: [Historical Count, part 3: Funnels and behavioral cohorts](https://amplitude.com/docs/analytics/historical-count-3).
