Skip to main content

Row Concepts

AQL is a data query language so it operates on the same objects like SQL or Excel: tables, rows and columns. In AQL, a table is a collection of rows, and each row has multiple columns.

Unlike Excel, AQL does not allow reference to a cell directly. Instead, the smallest unit of data that you can operate on is a row. When you write an AQL query, you are actually writing a query that operates on each row of a table.

Current Row

This is where the concept of "Current Row" comes in:

  • When AQL is processing the first row of the order_items table, the current row is that first row.
  • When AQL is processing the second row of the order_items table, the current row is that second row.
  • And so on...

In the context of a row, you can reference columns of that row directly by their names. Like in the query above, you can reference the quantity column of the current row by quantity or order_items.quantity.

You can also reference columns from other tables, though it requires more reading to understand. See Cross-model Calculations.

Iteration

The process of going through each row of a table is called “iteration”. In AQL, there are many functions that iterate through a table, such as:

  • select: iterate through a table and return a new transformed table.
  • filter: iterate through a table and return a new filtered table.
  • sum: iterate through a table and return the sum of the specified expression.
  • etc.

When you call these functions, the expression passed into the function will be evaluated for each row of the table, and the result of the expression will be returned as a new table or a scalar value

Row-level expression

A row-level expression is an expression that is evaluated in a context where the current row is available. Usually, this is the second argument of an iteration function like select or filter, but there are other cases where your expression is evaluated in a row-level context:

  • Dimension definition, which is evaluated over each row of the your model.dimension-definition
  • Measure when they are used in an exploration that contains dimensions. In this case, the measure is evaluated over each row of the exploration.measure

Let us know what you think about this document :)