CALCULATETABLE
Return rows rather than a single value
CALCULATETABLE applies modified filter context to a table-valued expression. It is useful when a downstream iterator, count, or DAX query needs the qualifying rows. CALCULATE instead evaluates a scalar expression. Neither changes source records. Use the clean Import model from Chapter 20. FactSales has five lines, RevenueUSD and Quantity; DimProduct contains ProductKey, Product and Category; DimRegion contains Region. Active one-to-many relationships filter the fact from each dimension. Use dimension columns for selections, no RLS, no other report filters, and fixed USD. Reuse the existing [Context Revenue] measure (SUM(FactSales[RevenueUSD])). Every formula below is a separate measure unless identified as a query or column. Expected results are fixture-derived; native DAX execution is NOT RUN.
Example 1 — Inspect qualifying rows in DAX Query View
EVALUATECALCULATETABLE( FactSales, DimRegion[Region] = "North", FactSales[Quantity] >= 2)ORDER BY FactSales[LineID]This query returns L01 only, with quantity 2 and revenue 24. Removing the region predicate returns L01, L03 and L05, totaling 120. A DAX query returns a table and does not automatically inherit report slicers. Run this independently in DAX Query View on the disposable model. Do not paste EVALUATE into a measure definition.
Example 2 — Consume a filtered table
Large Line Count =COUNTROWS(CALCULATETABLE(FactSales, KEEPFILTERS(FactSales[Quantity] >= 2)))Large Line Revenue From Table =SUMX(CALCULATETABLE(FactSales, KEEPFILTERS(FactSales[Quantity] >= 2)), FactSales[RevenueUSD])The table stays virtual in these measures. With no selection the count is 3 and revenue 120 USD. South returns 2 and 96 USD; North returns 1 and 24 USD. With North + Home there are no qualifying rows, so COUNTROWS and SUMX return BLANK here. KEEPFILTERS ensures a preexisting Quantity = 1 selection stays in conflict with Quantity >= 2 rather than silently being replaced.
Use the appropriate calculation surface
A table expression can also define a calculated table in an Import model, which materializes at model processing rather than reacting to report slicers. Do not create one solely to make a temporary measure filter. CALCULATE, CALCULATETABLE, KEEPFILTERS and REMOVEFILTERS have documented DirectQuery restrictions in calculated columns and RLS rules. The examples use Import measures and queries only; neither DirectQuery translation nor role behavior was tested.
Practice — inspect table and scalar answers
Predict the rows, count and revenue for South + Stationery and for North + Travel with the large-line measures. Change Quantity to exactly 1 and predict the intersection. Explain when a query is preferable to a scalar card.