Shape · Combine tables

As-of Join

Matches each row to the closest row in another table by a sorted key such as a time. For example, attach the price in effect at the time of each trade.

Also known as: Nearest match, merge_asof

How it works

Wire the tables into left and right and pick the Key column, which must exist on both sides. Direction chooses the right row for each left row: Backward takes the latest right key at or before the left key, Forward the earliest at or after it, Nearest the closer of the two, preferring the backward one on a tie. Match within groups adds columns that must be equal, such as a ticker. Tolerance drops a match whose keys are further apart than this, in the key's own units and in seconds for timestamps; blank means no limit. Inputs need not be sorted, and the output keeps the left table's order. A non-key column present on both sides gets a _left or _right suffix.

Inputs and outputs

Inputs

  • left — Table
  • right — Table

Outputs

  • data — Table

Settings

The Attributes panel of As-of Join, as in the app: the controls work, but nothing runs — there is no data behind it.

The same settings, as the Assistant writes them
{
  keyColumn: string
  byColumns?: string[]
  direction: "backward"|"forward"|"nearest"
  tolerance?: number
}

Example

Each trade should carry the price in effect when it happened. Join trades to prices on ts, match within ticker, direction Backward, tolerance 300 so a trade more than five minutes after the last quote is not matched.