# First matched pattern

The Pattern Match feature of ‘on the fly’ aggregations, allows you to return:

- different values based upon the first matched pattern
- the number of times a person has matched the first matched pattern

## First matched pattern

The Pattern Match algorithm stops when it encounters its first matched pattern and returns the Pattern Name to confirm that a particular pattern has occurred. However, when examining long lists of transactions, it can be useful to make selections based on some aspect of the pattern being matched. For example, when did the pattern start and/or end? How long did that pattern last? How many transactions did it take to complete the pattern?

The available options are:

- The transaction number on which the pattern started being matched
- The value of the ordering variable for the first value in the pattern
- The value of the item variable at the start of the pattern
- The transaction number on which the pattern ended being matched
- The value of the ordering variable for the last value in the pattern
- The value of the item variable at the end of the pattern
- The length of the pattern as a number of transactions
- The difference between the start and end values of the ordering variable

To access and select an option:

- Click on the **Return the** drop-down at the bottom of the Pattern Match aggregation window

The **Data Type** for the expression will automatically set and return the results according to the ordering variable selected:

## Text

- Pattern Name
- Start Transaction Value
- End Transaction Value

## Numeric

- Start Number
- End Number
- Pattern Length
- Pattern Order Span
- Number of Matches

**Start Order Value** &amp; **End Order Value** – can be Date, DateTime, Numeric or ordinal Selector and is, therefore, dependent upon the data type of the ordering variable used.

The Data Grid below demonstrates how the **Return the** values can be used to identify the start and end points for a **?1 - ?2 - ?1** positional wildcard Pattern Match aggregation, already applied:

> [!NOTE]
>
> Currently, values are returned based on the first matched pattern. If you want to restrict this to recent patterns, you can use a transactional filter selection based on date.

## Number of matches

Going beyond the first matched pattern, in the **Return the** drop-down, there is the **Number of Matches** option which allows us to establish how many times a person has matched the first matched pattern.

For example:

- A person with transactions of **ABCAB**, where the pattern match is **AB**, returns a value of 2

For patterns with repeating values, it is possible to determine if each matched pattern should allow overlaps or not. This is achieved using the check-box that appears when you select **Number of Matches**:

For example, a person with transactions **AAAA**, where the pattern match is **AA**, returns 3 with overlaps and 2 without

> [!NOTE]
>
> Each matched pattern will have a different start transaction. This is seen in the results returned from the following pattern definition:

Based on allowing overlaps, for the Destination variable, person URNs 119535 and 119755 both have 8 holiday bookings to the United States and return a count of 4 for the number of overlapping matches of 5 bookings to the same destination:

Based on the transactions for Person URNs 119569 and 119656, a count of just 1 is returned:
