Module 7 · Power BI DAX
Table functions and virtual tables
Build tables inside a measure with FILTER, VALUES, SUMMARIZE and ADDCOLUMNS, count the customers that meet a condition, and test your tables in DAX query view.
About 25 minutes
The problem
The commercial director asks three questions for the quarterly review:
- How many customers spent more than ₦10m in 2025?
- How many new customers did we win in 2026?
- How many customers buy from all four of our categories?
None of them is a sum or an average of a column. Each one is "count the customers that meet a condition", and the condition is itself a calculation. To answer them, a measure has to build a table of customers in memory, test each one and count the survivors. That's what table functions are for.
The concept
Some DAX functions return a table rather than a value. You can't show a table in a card, but you can count it, iterate it or use it as a filter.
| Function | Returns |
|---|---|
VALUES ( column ) | the distinct values of a column visible in the current filter context |
ALL ( table or column ) | every row or value, ignoring filters |
FILTER ( table, condition ) | the rows of a table where the condition is true, tested row by row |
SUMMARIZE ( table, column, … ) | the distinct combinations of columns that exist in a table |
ADDCOLUMNS ( table, "Name", expression ) | the table with calculated columns added |
CALCULATETABLE ( table, filters… ) | a table evaluated under modified filters |
The pattern behind all three questions:
DAX
COUNTROWS ( FILTER ( VALUES ( orders[customer_id] ), <condition per customer> ) )FILTER iterates the customers, so the condition runs in a row context. Use a measure in the condition and context transition calculates it for each customer.
Filter direction matters in table logic too
You might try to count each customer's categories with CALCULATE ( DISTINCTCOUNT ( products[category] ) ). It returns 4 for everyone: filters flow from products to orders, never from orders back to products. Count the categories through the fact table instead:
DAX
COUNTROWS ( SUMMARIZE ( orders, products[category] ) )SUMMARIZE lists the categories that actually appear in the customer's order lines.
DAX query view
Power BI Desktop's DAX query view (the fourth icon on the left) runs a query and shows the resulting table, so you can see a virtual table before you count it:
DAX
EVALUATE
ADDCOLUMNS (
VALUES ( customers[customer_name] ),
"Revenue 2025", CALCULATE ( [Revenue], 'Date'[Year] = 2025 )
)
ORDER BY [Revenue 2025] DESCExample
DAX
Big Customers =
COUNTROWS (
FILTER ( VALUES ( orders[customer_id] ), [Revenue] > 10000000 )
)
New Customers =
VAR PeriodStart = MIN ( 'Date'[Date] )
RETURN
COUNTROWS (
FILTER (
VALUES ( orders[customer_id] ),
CALCULATE ( MIN ( orders[order_date] ), REMOVEFILTERS ( 'Date' ) ) >= PeriodStart
)
)
All-Category Customers =
COUNTROWS (
FILTER (
VALUES ( orders[customer_id] ),
CALCULATE ( COUNTROWS ( SUMMARIZE ( orders, products[category] ) ) ) = 4
)
)New Customers takes the customers who bought in the period, works out each one's first ever order date (removing the date filter), and keeps those whose first order falls inside the period. PeriodStart is a variable because it must be the start of the visual's period, captured before FILTER starts iterating.
Walkthrough
- Open DAX query view and run the
EVALUATEquery from the concept section. You'll see 90 rows: the virtual tableBig Customersfilters. - Add the three measures, and put them in a table by
Date[Year]. - Check
Big Customersfor 2025 in DAX query view: addFILTER ( …, [Revenue 2025] > 10000000 )around theADDCOLUMNSand count the rows. - Try the wrong version of the category count,
CALCULATE ( DISTINCTCOUNT ( products[category] ) ) = 4. Every buying customer passes. Then switch back. - Add
customers[channel]to the table. Which channel do the new customers of 2026 come from?
Practice
Practice
How many Big Customers (revenue over ₦10m) were there in 2025?
Practice
How many New Customers did Kolanut win in 2026?
Practice
How many customers bought from all four categories in 2026?
More practice
Drill · optional
How many customers bought from exactly one category in 2026?
Drill · optional
Legal data: how many clients have more than ₦20m of invoices in total? Use COUNTROWS(FILTER(VALUES(matters[client_id]), …)) with invoices related to matters.
Check your understanding
Answer every question to check.