Table expressions
Build a table for the next calculation
A table expression produces rows and columns for another expression or a query result. It need not become a persisted model table. Decide whether to preserve the original rows, select a new set of columns, or group rows into summaries. Use the isolated Import table DiscountSales from labs/dax-iterators/discount-sales.csv; no relationships or RLS are required. Text: LineID and Region. Whole numbers: Quantity, UnitPriceUSD, DiscountPercent and GrossUSD. DiscountPercent is in percentage points (10 means 10%, not 0.10). GrossUSD is the pre-discount line amount. Five ordinary sale lines and one synthetic zero-quantity test line are present. Fixed USD, no taxes, returns or rounding policy beyond this integer-valued fixture. All results below are expected from independent fixture arithmetic; native DAX execution is NOT RUN. Create each named measure separately. DAX Query View queries run separately and do not inherit report slicers. Reuse [Net Revenue] and [Units]. Run the following EVALUATE statements separately, without DEFINE or report filters.
Example 1 — Filter and project rows
EVALUATEVAR DiscountedRows = FILTER(DiscountSales, DiscountSales[DiscountPercent] > 0)VAR WithNet = ADDCOLUMNS(DiscountedRows, "LineNet", DiscountSales[GrossUSD] * (1 - DiscountSales[DiscountPercent] / 100))RETURN SELECTCOLUMNS(WithNet, "Line", DiscountSales[LineID], "NetUSD", [LineNet])ORDER BY [Line]Expected output:
| Line | NetUSD |
|---|---|
| L02 | 27 |
| L03 | 27 |
| L05 | 30 |
FILTER removes nonqualifying rows; ADDCOLUMNS retains the input columns and introduces LineNet for each retained row; SELECTCOLUMNS emits only the named output columns. Projection does not automatically deduplicate rows. This example references the extension column as [LineNet], not WithNet[LineNet]. Neither function writes to the imported table. ORDER BY requests a stable display order.
Example 2 — Group rows before reporting
EVALUATESUMMARIZECOLUMNS(DiscountSales[Region], "Units", [Units], "NetUSD", [Net Revenue])ORDER BY DiscountSales[Region]EVALUATEADDCOLUMNS(SUMMARIZE(DiscountSales, DiscountSales[Region]), "Units", [Units], "NetUSD", [Net Revenue])ORDER BY DiscountSales[Region]Both return the following for this single-table, unfiltered fixture:
| Region | Units | NetUSD |
|---|---|---|
| North | 4 | 101 |
| South | 5 | 57 |
| Zero | 0 | 0 |
SUMMARIZE creates groups from its table input. ADDCOLUMNS then evaluates the measures per group; measure invocation supplies context transition. SUMMARIZECOLUMNS groups model columns and evaluates named scalar expressions in their group context; groups for which all supplied expressions are BLANK are normally omitted (zero is not BLANK). The two patterns are not generally interchangeable for arbitrary tables, relationships, filters or engine versions. No totals are added automatically. Do not average these three regional totals to compute the overall net revenue.
Consume virtual tables at the intended grain
Net From Region Groups =SUMX(SUMMARIZE(DiscountSales, DiscountSales[Region]), [Net Revenue])Expected 158 USD with no filters because the region groups partition the sale lines and net revenue is additive. For a weighted price, instead recompute the ratio of overall net and units. A nested iterator over region and then sale line can be correct but needlessly expensive; the direct sale-line measure is simpler here. A scalar measure cannot return the output of SELECTCOLUMNS directly. A calculated table can persist such results at processing time, which is a different calculation surface from a query or measure. SUMMARIZECOLUMNS context-transition and filter semantics have evolved across engine versions; this lesson deliberately uses a top-level query only. Verify installed build and function-specific DirectQuery/RLS restrictions before porting these Import examples.
Practice — build a high-discount audit
Modify the first query to keep discounts of at least 25 percentage points. Predict the returned rows and total net. Modify the second query to group by Region and add the [Weighted Net Price] measure from lesson 1. Predict the Zero result and explain why the group still appears when Units is included.