Skip to content
Proposal for a new site by Genesis Innovation, built from his public LinkedIn profile. Not his official site.

Wiki Power BI and DAX

Row context and filter context

Every DAX expression runs inside a context. The filter context restricts the rows a measure sees; the row context points at a current row.

A DAX expression never runs "in a vacuum": the result depends on the context in which it is evaluated. There are two kinds, and mixing them up is the source of most measures that "don't add up".

The filter context is the set of active filters over the tables of the model: rows and columns of the visual, slicers, page filters and the filters propagated through relationships. The measure is evaluated once per cell of the visual, each one with its own filter.

The row context is the "current row" of a table. It exists in calculated columns and inside iterators such as SUMX. It does not filter anything: it only says which row to read the values from.

DAXRuns in Power BI
-- Calculated column in Sales: there is a row context
Line Cost = Sales[Quantity] * RELATED ( Product[Cost] )

-- Measure: the filter context comes from the visual
Revenue = SUM ( Sales[Amount] )

RELATED reads, in the current row, a value from the table on the one side of the relationship (here, the cost of the product of that sale). In a visual with Product[Category] on the rows, the Revenue measure for each row is the sum of only the Sales rows whose product belongs to that category. The total of the visual has no category filter and sums everything.

Pitfall

Using a raw column inside a measure, outside an iterator:

DAXRuns in Power BI
Double Revenue = Sales[Amount] * 2

Measures have no current row, so this expression raises an error: DAX does not know which of the many rows of Sales[Amount] to use. Write SUM ( Sales[Amount] ) * 2 or, if the calculation has to be done row by row, SUMX ( Sales, Sales[Amount] * 2 ). When in doubt, ask yourself: "is there a current row here?". If not, the column needs an aggregation.

Sources

Shared knowledge from Genesis Innovation. Not a claim about the person behind this site.