Skip to content

Automatic translation — the Portuguese version is the reference. View in Portuguese

Updated on 2026-10-04

Row context and filter context

The core idea of DAX-style formulas — when a measure is evaluated row by row and when it's evaluated within a slice.

On this page (9)

A conceptual page. If there's one concept that separates a "spreadsheet" from an "analytical model", it's this one: context. Understanding row context and filter context is what makes your measures give the right number in any visual. The function reference is in Measures, formulas and KPIs and in the formulas catalog; here we explain the mental model.

Examples use the synthetic workspace Comércio Aurora Ltda (aurora), the vendas fact table and the produtos, filiais and calendario dimensions.


The two questions every measure answers#

When a measure is calculated, the engine answers two things:

  1. Over which rows? — that's the filter context.
  2. One row at a time, or the whole set at once? — that distinguishes row context from aggregation.

Row context#

It exists when the formula is evaluated one row at a time. That's the case for calculated columns and for what happens inside an iterator.

  • Calculated column margem = valor - custo: for each row of vendas, the engine knows the valor and custo of that row and does the subtraction. There's no sum here — it's row by row.

A bare column (e.g., valor) only makes sense in row context. If you use it in an aggregated measure without saying how to aggregate it, the editor refuses with an error in Portuguese ("coluna solta em medida agregada" — bare column in an aggregated measure) — because "the value" of a set of rows is ambiguous.


Filter context#

It's the set of visible rows at the moment of the calculation, defined by everything that slices the screen: the visual's axis/legend value, slicers, drill-down, cross-filtering. The same measure gives different numbers in each cell because each cell has a different filter context.

Receita = SOMA(valor) in a matrix by produtos.categoria × month: each cell sums only the sales of that category in that month — not because the formula changed, but because that cell's filter context is different.

Note

Golden rule: you almost never "pass" the filter to the measure. The visual and the slicers already create the context; the measure just sums what's visible. Modifying the context is the exception, and that's what CALCULAR is for.


Modifying the context: CALCULAR#

CALCULAR (the equivalent of DAX's CALCULATE) is the function that changes a measure's filter context. It takes the base measure and applies (or removes) slices:

  • CALCULAR(MEDIDA('Receita'); categoria = "Bebidas") — forces Bebidas only, ignoring whatever is selected in that dimension.
  • CALCULAR(MEDIDA('Receita'); TUDO()) — removes all of the group's filtering (not just products — TUDO() takes no argument), useful for calculating "share of the total": MEDIDA('Receita') / CALCULAR(MEDIDA('Receita'); TUDO()).
  • REMOVER_FILTROS, FILTRAR, TUDO and the modifiers combine with one another with deterministic precedence — the same combination always produces the same number (guaranteed by the reference test suite).

Context transition (the trick)#

When you use a measure inside an iterator (which runs in row context), context transition happens: the current row becomes a filter, and the measure is evaluated as if that row were the slice.

Example: SOMAX(produtos; MEDIDA('Receita')) goes through each product (row context) and, for each one, evaluates MEDIDA('Receita') filtered by that product (transition), then adds everything up. That's what makes "revenue of each product's best month" possible, along with calculations that a direct sum can't do.

Common iterators: SOMAX, MEDIAX, CLASSIFICAR, PRIMEIROS_N. They all evaluate the expression per row of the table they receive.


Time intelligence is filter context over dates#

Functions such as ACUM_ANO (YTD), MESMO_PERIODO_ANO_ANTERIOR and DESLOCAR_PERIODO aren't magic: they rewrite the date filter context. ACUM_ANO replaces "this month" with "from January 1 to the end of this month". That's why they require a calendar dimension linked to the fact table — see Tutorial: calendar table and Measures and time comparisons.


Common mistakes#

  • Summing a row-level calculated column thinking it's a measure. A calculated column is row by row; for the total, wrap it in an aggregation (SOMA(...)).
  • Expecting a slicer to "get into" the measure on its own when you used TUDO. If the measure removes the filter with TUDO/REMOVER_FILTROS, the slicer for that dimension no longer slices it — that's the requested behavior, but it surprises anyone who forgot.
  • Using a measure inside an iterator without wanting a transition. Remember that a measure reference (MEDIDA('...')) inside SOMAX is evaluated per row, not over the whole set.

Limits and caveats#

  • It's a genuine DAX-like language (real filter context), but it's not full DAX: there are no virtual tables in the engine, and relationships live in SQL. We don't claim full parity with DAX.
  • Division by zero → EMPTY; DATA − DATA (date minus date) gives a teaching error asking for DATADIF.

Related#


Last reviewed: 2026-09-08.

Related links